繁体   English   中英

如何使用EventReceiver在SharePoint 2010中以编程方式更改页面名称和URL

[英]How to programmatically change page name and url in SharePoint 2010 with EventReceiver

我要实现的目标很简单。 当用户在SharePoint 2010中创建新页面时,我想删除特殊字符并将页面名称/ URL截断为一定数量的字符。

例如:用户在“创建新页面”对话框中输入“我要使用超长名称创建此页面!@#$%^^&** _ +”,则实际创建的页面为“ extralongname.aspx”

我得到了删除特殊字符并截断部分。 我只是无法更改页面名称/网址。

任何想法?

问候,

真的很简单。 您只需要更改FileLeafRef字段的值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();
}

我通过搜索类似问题找到了您的问题。

我想您已经解决了这个问题。 也许它可以帮助遇到同样问题的其他人。

您是否正在使用SPSecurity Object进行此操作?

例如。

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();
   }

});

这是因为用户可能没有执行此操作的权限。

但这应该可以解决问题!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM