Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How to move an item from custom list root location to sub folder programmatically (in Event Receiver (ItemAdded))?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

You can identify a custom list's root folder using SPList.Rootfolder property and corresponding subfolders could be accessed using SPList.Rootfolder.SubFolders[index].

While adding the list item, make sure that it is added to the correct folder path.

SPListItem listitem = list.Items.Add(folder.ServerRelativeURL,SpFileSystemObjectType.File)

Sample code might look like this.

     using (SPWeb web = properties.OpenWeb())
       {
           SPList list = web.Lists["Test"];

           if (properties.List.Title == list.Title)
           {
               foreach (SPFolder folder in properties.List.RootFolder.SubFolders)
               {
                   if (folder.Name == "Specific Folder Name")
                   {
                       SPListItem listItem = list.Items.Add(folder.ServerRelativeUrl, SPFileSystemObjectType.File);
                       listItem["FieldName"] = properties.ListItem["FieldName"];
                       listItem.Update();
                   }
               }
           }

       }
share|improve this answer
add comment

This solution allow you to move to any folder in same or different list http://think4code.blogspot.com/2012/03/move-list-item-splistitem-to-sub-folder.html

share|improve this answer
1  
We require relevant answers and disclosure of any affiliation with products or websites. Please see May I promote products or websites I am affiliated with here? for guidelines. –  SPDoctor Jul 5 '12 at 22:30
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.