Following code will do that functionality. Like how we are renaming a file through UI, we have to first check-out the file and after renaming the file we have to check-in it.
SPSite oSite = new SPSite ("http://<sitename>/");
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists["Shared Documents"];
SPListItem oListItem = oList.Items; //taking the first list item
oListItem["Name"] = "xyz";
oListItem.File.CheckIn("file name has been changed");
I don't know if this is possible.. but i tried this with lists. im about to rename an attachment filename. but i get an error 'Object reference not set to an instance of an object.'
can you help me with this? i'm a newbie in sharepoint and i already tried everything found on the net that would help me rename attachment filenames but still fail. thanks in advance!
How can one rename a file using SharePoint Client OM?
TO rename a file using the Client Object Model:
string comment = "Testing file rename";