Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to create a web part to place on a document set web part. How would I get the context of the document set and the documents within the set from within the web part?

thx

share|improve this question

2 Answers 2

up vote 4 down vote accepted

The url for the document set welcome page includes an ID in the query string, so you can use this parameter to find the document set:

http://server/MyDocumentLibrary/Forms/MyDocumentSet/docsethomepage.aspx?ID=2

var id = Convert.ToInt32(HttpContext.Current.Request.QueryString["ID"]);
SPListItem item = SPContext.Current.Web.Lists["MyDocumentLibrary"].GetItemById(id);
var dsItem = Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet.GetDocumentSet(item.Folder);

NOTE: You will need to add a reference to Microsoft.Office.DocumentManagement

share|improve this answer
    
Do you know how I can determine the library name knowing only the id of the item? i.e. id –  David Jun 9 '11 at 19:44
    
In addition to the ID parameter, the welcome page also includes these query string parameters: FolderCTID (the content type), List (the List ID). So you can get the listId = ...QueryString["List"] and then: SPContext.Current.Web.Lists[new Guid(listId)] –  Laurie Jun 9 '11 at 20:22
    
If your document set is in a sub folder (not at the root of the document library) you have to specify the RootFolder parameter. E.g. server/MyDocumentLibrary/Forms/MyDocumentSet/… –  Bernd Rickenberg yesterday

http://office.microsoft.com/en-us/sharepoint-server-help/customize-the-welcome-page-for-a-document-set-HA101782474.aspx says "The Document Set Welcome page is a Web Part page that can be edited just as you would edit any Web Part page". Any further questions?

share|improve this answer
1  
I understand that the welcome page is a web part page. This doesn't answer the question. If I put a web part on the welcome page (custom web part), programmatically how do I get a context to the current document set within the web part. I want to perform operations on the documents within the current document set and to do this i need to get some sort handle the current set. thx –  David Jun 5 '11 at 11:15
1  
This wasn't quite clear from how you formulated the question. Please edit the question to make it more specific. The question title is "how to add a webpart" while in the body you ask another question "how to get the context of the displayed document set". –  Alexey Krasheninnikov Jun 6 '11 at 9:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.