how to get the context of current document set in a custom web part placed on document set welcome page?
-
16-10-2019 - |
Pergunta
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
Solução
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
Outras dicas
var item = SPContext.Current.ListItem;
will get you the ListItem, then
var folder = item.folder;
will get you the folder matching the item, and
var docset = DocumentSet.GetDocumentSet(folder);
will get you the document set for that folder. Though most things you might want to do (like getting/setting fields) really only need the listitem or maybe the folder.
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?