Friday, February 8, 2013

SharePoint 2010 : Copying Document sets programatically from one library to another with metadata


Many of you must have come across situations where you have to move the already created Document sets (with a whole bunch of documents in it) from one location to another due to organization re-structure or may be introduction of some new ways of working.
I did come across similar situation where I had to move 5000 Document Sets with documents in them counting 60,000 in total from one library to another. In my case the document sets are within a folder in the source library. Since I am not a folder-loving developer, I tend not to use them frequently.

So here is my code to copy the document sets from source library and put it into the destination library without folders.
Please note:

  • Metadata columns (for Document Set and Document) should read same in the destination library and the source library if you want them to be copied along the process
  • Make sure you have set up Document Set content types in the destination library
I am using a console application so add reference to  
  • Microsoft.SharePoint
  • Microsoft.Office.DocumentManagement.DocumentSets
and make sure your target machine and build is set to proper values.

using (SPSite site = new SPSite("http://sharepointsite"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPFolder folder = web.GetFolder("folderURL"); // sharepointsite/library/folder

                    SPList sourceList = web.Lists["sourcelistname"];

                    SPQuery query = new SPQuery();                    
                    query.Folder = folder;


                    SPListItemCollection itemColl = sourceList.GetItems(query);
                    foreach (SPListItem sourceItem in itemColl)
                    {                        

                        if (sourceItem.ContentType.Name == "Document Set")
                        {
                            DocumentSet documentSet = DocumentSet.GetDocumentSet(sourceItem.Folder);

                            SPList targetList = web.Lists["targetListName"];

                            SPContentTypeId contentTypeId = targetList.ContentTypes["destination document library"].Id;

                            byte[] documentSetData = documentSet.Export();

                            string documentSetName = documentSet.Item.Name;

                            SPFolder targetFolder = targetList.RootFolder;

                            Hashtable properties = sourceItem.Properties;

                            DocumentSet.Import(documentSetData, documentSetName, targetFolder, contentTypeId, properties, web.CurrentUser);
                        }
                    }
                }
            }

SharePoint 2010 : No available sandboxed code execution server could be found

This might cause your sand boxed cause to seize and not perform their regular functions.

You need to re-start(Stop and Start again) the Microsoft SharePoint Foundation Sand boxed Code Service from services on server. You might see that it is already started, still just Stop the service and Start again.

• Central Administration > System Settings > Servers > Manage Services on server > Start the Microsoft SharePoint Foundation Sand boxed Code Service

Try this at first instance which might resolve your error. If this doesn't work, you can email me and we can work it out together.


Monday, August 6, 2012

Installing SharePoint Server 2010 on Windows 7 Home Premium

Follow the following post for installing SharePoint Server 2010 on Windows 7 Home Premium


http://msdn.microsoft.com/en-us/library/ee554869.aspx

Follow Step 8 and Step 9 properly as they are very important ones when dealing with Windows 7 Home Premium.
Reason: Win 7 Home Premium does not support Windows authentication as it is available in Professional and Ultimate versions, so in order to make SharePoint run properly you need be extra careful while step 8 and step 9.

However, you have done everything properly and installed SharePoint properly with all its pre-requisites and then when you try to open Central Admin or your root site, you get a blank page, try the following things:
- Go to IIS Manager, and select Sites > SharePoint : 80

- Double Click Authentication and Right Click on Basic Authentication and enable it.

- Try logging in to central admin with your system admin account. If this does not solve your problem, try next one.

- Disabling LoopbackCheck

- Follow Method 2 from this url http://support.microsoft.com/kb/896861


Hopefully this will solve your issue.