Wednesday, June 4, 2014

SharePoint: Read Metadata(properties) values of a document set in a document library using C#.Net.


Solution: I used methods from sever object model(Microsoft.SharePoint Api) to read a particular document set as I had list id and item id(document set id). Once I got the document set object, I used hashtable to contain fields and its values. I used that hashtable for further processing. I hope this would help some one...Cheers…J

Hashtable hashtableMetaData = null;

 private void ReadDocumentSet()
        {
            //Get the document library based on list ID
            using (SPWeb currentWeb = SPContext.Current.Web)
            {
                SPList spList = currentWeb.Lists[listId];
                //Get the document set based on item id
                DocumentSet documentSet = DocumentSet.GetDocumentSet(spList.GetItemById(itemId).Folder);

                SPListItem spListItem = documentSet.Item;

                //Collect MetaData
                hashtableMetaData = new Hashtable();

                string str = string.Empty;
                foreach (SPField field in spListItem.Fields)
                {
                    if (spListItem[field.Title] == null)
                    {
                        hashtableMetaData[field.Title] = null;
                    }
                    else
                    {
                        hashtableMetaData[field.Title] = spListItem[field.Title].ToString();
                    }
                }

            }
        }

No comments:

Post a Comment