Monday, December 21, 2015

Rename file in a document library folder

if (properties.BeforeUrl != properties.AfterUrl)
{
string[] onp = properties.BeforeUrl.Split('/');
string ofn= onp[onp.Length - 1]; // get the old file name
string name= Path.GetFileNameWithoutExtension(ofn);
string[] nnp = properties.AfterUrl.Split('/');
string nfn = nnp[nnp.Length - 1]; //get the new file name

string furl = doculibrUrl + "/Shared Folder/" + name+ ".tiff";
SPFile file = web.GetFile(fURL);
if (file.Exists)
{
    file.Item["Name"] = nfn;
    file.Properties["Title"] = nfn;
    file.Item.Update();                               
}
return;
}

No comments:

Post a Comment