only My site

Monday, October 22, 2012

SPFolder Rename Trick

The SPFolder object properties are mostly read-only, so I am afraid you are up poops creek sans paddle with that. The way that I have gotten accustomed to programmatically renaming things for files (like an SPFile object) is to call the name column:

file.Item["Name"] = string.Format("{0}", yourClassVar)

then doing a:

file.Item.Update();

For renaming a folder, it is kinda tricky, since it is read-only propreties. BUT, you can do a MoveTo()

Like this won't work:

SPFolder.Name = "NewFolderName";

But this will:

SPFolder.MoveTo("brandspakningnewSPFolder.Name");

No comments: