0

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?

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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