2

What I want to achieve is simple. When user create a new page in SharePoint 2010, I want to remove special character and truncate the page Name/URL to a certain number of characters.

Eg: user type in "I Want To Create This Page With An Extra Long Name !@#$%^^&**_+" in the create new page dialogbox, the actual page that get create is "extralongname.aspx"

I got the remove special character and truncate part. I just can't change the page Name/Url.

Any idea?

Regards,

Ken

Ken Thai
  • 76
  • 4
  • Hmm, it has been more than a week and no one reply. Does this mean no one in the whole world know the answer (even from Microsoft) or the problem is too hard to solve? – Ken Thai Dec 18 '11 at 23:10

2 Answers2

0

It is really easy. You just have to change the value of field FileLeafRef.

using (SPSite site = new SPSite("https://sharepoint-site.domain.com"))
using (SPWeb web = site.OpenWeb())
{
    SPList list = web.Lists["Your list"];
    SPListItem item = list.GetItemById(1);

    // next row is important
    item[SPBuiltInFieldId.FileLeafRef] = "Your page url and title.aspx";
    item.Update();
}
Lukas Nespor
  • 1,238
  • 1
  • 14
  • 22
0

I found your question by searching for an simliar problem.

I guess you've solved the problem in the meantime. Maybe it can help other people having the same issue.

Are you doing this with the SPSecurity Object?

eg.

SPSecurity.RunWithElevatedPrivileges(delegate(){
SPSite site = new SPSite(siteUrl); //You need the url here

   using(SPWeb web = site.OpenWeb();
   {
      web.Title = "The new Title";
      web.Update();
   }

});

It's because the user may not have the privileges doing this.

But this should do the trick!

PatrickP
  • 80
  • 2
  • 9