Posts

Showing posts from July, 2014

How to move SharePoint list items to a folder and subfolders in the same list using C# programmatically?

Image
It was really simple at the end, but it took my whole day for writing the utility to achieve the desired results. However, the tricky part of the utility was how i can move the items to a sub folder of the list. For example there is a folder 2014 and it contains 12 folders of each month. You want to move the item inside a folder. Keep in mind the hierarchy of SharePoint. Follow below steps. 1. Get SPWeb 2. Get SPList 3. Get List Folders 4. Get Sub Folders of Folders 5. Copy the Item I have divided the steps into Methods. Code below. Get Site,Web and list Objects and Passing them to a method InsertItemIntoFolder. using (SPSite site = new SPSite( "Your Site URL" )) {     using (SPWeb web = site.OpenWeb())     {         SPList sourceList = web.Lists.TryGetList( "Your List Name" );         List < Guid > IID = new List < Guid >();         foreach (SPListItem item in sourceList.Items)         {