My environment is sharepoint 2010 and vs 2010.
I already have an OOTB document library that I am using and I wanted to know how I can add a tag or keyword to a METADATA column.
I am using the same document library in all subsites and so would like to tag the uploaded document with the name of the current site (ie if it's being used in a subsite, that subsite's name would be the tag).
Would I need to build a custom document library or some sort of add-on webpart that attaches to the existing document library?
If you could provide some code samples if any that would be appreciated.
thanks,
KS
UPDATED
So I deployed the below EventReceiever, however it does not appear to be doing anything - when I attach the debugger it says the break point could not be hit no symbols loaded - what should I do?
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item is being updated.
/// </summary>
public override void ItemUpdating(SPItemEventProperties properties)
{
SPWeb Site = null;
using (SPSite SiteCollection = new SPSite(properties.ListItem.ParentList.ParentWeb.Site.ID))
{
Site = SiteCollection.OpenWeb(properties.ListItem.ParentList.ParentWeb.ID);
}
//if (properties.ListId.Equals("eaff7d9c-9209-47cc-af84-1488faefe793"))
//{
string fieldInternalName = properties.List.Fields["TaxKeyword"].InternalName;
properties.AfterProperties[fieldInternalName] = Site.Name;
//}
}
}
MORE UPDATES CurrentSite is always nothing (the root) whether I use the document library webpart in a subsite or not.
public override void ItemAdded(SPItemEventProperties properties)
{
string CurrentSite = properties.Web.Url;
base.ItemAdded(properties);
}
CONCLUSION It is not possible to retrieve the subsite name from an event receiver fired from a document library which "lives" in the root, but displayed on a webpart in a subsite.
I will have to try something else!
thanks to all.