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

Is there a way to programmatically move an existing list item (SPListItem) to a folder or do I need to make a new item that is a duplicate of the list item in the folder in question and then delete the old one?

share|improve this question
add comment

2 Answers 2

It is not explicitly a file but you can still use it as one. Here's an example I've used before:

SPListItem item;
SPList list;
SPWeb web;
string DestinationFolderPath;
SPFile file = web.GetFile(item.Url);
string destinationUrl = list.RootFolder.ServerRelativeUrl.TrimEnd(new Char[] { '/' }) + "/" + DestinationFolderPath + "/" + item.ID.ToString() + "_.000";
file.MoveTo(destinationUrl);

You could make a new item that is a duplicate but you'll run into issues if you have lookups to that item. Since the new item will have a new ID, the lookup will be broken.

share|improve this answer
add comment

If its a file you can use the SPFile.MoveTo command.

share|improve this answer
    
SPListItem Not a file. –  Robert Kaucher Sep 14 '12 at 23:11
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.