[SharePoint] Get document set object information using code

Source: Internet
Author: User

What is a document set?

Document set is a new feature in SharePoint 2010. It helps us better manage documents in Sharepoint. The document set provides a unified User Interface (UI), metadata, and Behavior for all documents stored in it. It makes the relationship between documents and SharePoint sites more closely. In fact, we can regard the document set as a more powerful folder, because the document set content type is derived from the folder content type..

 

How to obtain document set information

When creating a document set content type, we can set the fields in this content type as shared columns. The value of shared columns can be automatically synchronized to all documents in the document set.

During development, if you want to obtain the content of these shared columns from the document objects in the document set, you can obtain the value of shared columns just like getting common list fields.

Splistitem m_item = file. item; string m_year = m_item ["year"]. tostring (); string m_term = m_item ["term"]. tostring (); string m_examdate = m_item ["Exam time"]. tostring ();

 

What if you want to obtain the content of non-shared columns in the document set? What should I do? For example, the name field of the document set or some hidden fields cannot be set as shared columns.

You need to find a way to obtain the documentset object of this document set. To obtain the documentset object, you need to use documentset. getdocumentset (spfolder folder) method. This method requires a spfolder object as the parameter. As mentioned earlier, you can regard the document set as a folder, so we can use the followingCodeTo obtain the spfolder object.

 
Spfolder folder = item. Web. getfolder (item. url. substring (0, item. url. lastindexof ('/')));

With the folder object, you can easily obtain the documentset object of this document set.

Documentset docset = documentset. getdocumentset (folder );

 Then, you can use the item attribute of the documentset object to obtain the splistitem object associated with this document set object. In this case, you can easily obtain the content of each field in this document set.

Try {splistitem item = spcontext. current. listitem; spfolder folder = item. web. getfolder (item. URL. substring (0, item. URL. lastindexof ('/'); documentset set = documentset. getdocumentset (folder); writer. writeline ("contenttype: {0} <br/>", item. contenttype. name); writer. writeline ("title: {0} <br/>", item. title); writer. writeline ("welcomepageurl: {0} <br/>", set. welcomepageurl); writer. writeline ("itemcount: {0} <br/>", set. folder. itemcount); writer. writeline ("welcomepage fields: <br/>"); documentsettemplate template = set. contenttypetemplate; welcomepagefieldcollection fields = template. welcomepagefields; foreach (spfield field in fields) {writer. writeline ("{0} <br/>", field. title) ;}} catch (exception ){}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.