[英]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.