how to get the context of current document set in a custom web part placed on document set welcome page?

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/13926

문제

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

도움이 되었습니까?

해결책

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

다른 팁

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top