Monday, April 9, 2012

Change document library file name programmatically


You must be wondering what is new in this. We can certainly change the name or the title of the document inside document library from code.

Well, no. we cannot do that right away as Name and Title of SPFile are read only fields. As each document is SPFile inside document library we might think that changing name and title field would do the job. But it’s not. Check the below images. Properties are read only.





So what can be done? Well as we all know that each document inside document library is not only SPFile but also SPListItem.

Now these are my shared documents and check the document name.



And let’s re write our code in this way.



And when you execute



I hope this will help.

No comments:




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com