Capturing Folder Name in the document library column
-
Wednesday, April 11, 2012 2:44 PM
Hello,
I have one document library and it has folders inside known as A, B, and C. Now whenever document is uploaded inside any of the above folders I need to capture current folder name in the one of the column of the document library. Can any one help to resolve this issue? I have only OOB, or Javascript / jQuery option in the current site. Thank you so much in advance.
All Replies
-
Saturday, April 14, 2012 9:36 AMModerator
Hi ShareStepper,
As far as I know, the Jacascript/JQuery is difficult to achieve it. After my search, there is no OOB function. So, I suggest you to do it with event handler. The following is sample code.
public override void ItemAdding(SPItemEventProperties properties) { //base.ItemUpdated(properties); SPListItem item=properties.ListItem; string foldername = item.Folder.Name; item["YourCustomColumn"] = foldername; using (SPSite thisSite = new SPSite(properties.WebUrl)) { SPWeb thisWeb = thisSite.OpenWeb(); thisSite.AllowUnsafeUpdates = true; thisWeb.AllowUnsafeUpdates = true; item.Update(); } }More about event handler, you can refer to the following link.
http://msdn.microsoft.com/en-us/library/ff407274.aspx
Thanks,
Jack
- Edited by Jack-GaoMicrosoft Contingent Staff, Moderator Saturday, April 14, 2012 9:40 AM
- Marked As Answer by ShareStepper Monday, April 16, 2012 1:00 PM

