Update Filename or List Item name programmatically in SharePoint/WSS
Filed in Sharepoint on Mar.09, 2010
As simple as it sounds, it ain’t simple.
you would of thought the following would work:
SPFile file = web.GetFile(strUrl);
file.name = “mynameFilename.txt”;
file.Update();
does not compute..
There are 2 ways I’ve found of accomplishing this:
1. using the SPFile.MoveTo method:
string strUrl = “http://mysharepointsite/myolddocumentlibrary/Filename.txt”;
string newFileUrl = “http://mysharepointsite/mynewdocumentlibrary/mynewFilename.txt”;
SPSite site = new SPSite(”http://mysharepointsite”);
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true; // this will stop it [...]
