2012-03-12 25 views
0

我有一個發佈頁面代表一個人(如果您願意的話,聯繫表單),並且我想讓用戶可以編輯表單中的一些信息,年齡,地點...)。以編程方式更新當前頁面屬性時的權限問題

所以我有一個編輯按鈕,打開一個彈出式窗口,其屬性允許用戶更新。

現在的問題是:當用戶按下保存按鈕時,拋出異常,說用戶沒有更新頁面的權限。這發生在我嘗試無論是檢出或更新頁面

我的代碼是這樣的:

Guid siteId = SPContext.Current.Site.ID; 
      Guid webId = SPContext.Current.Web.ID; 
      SPSecurity.RunWithElevatedPrivileges(delegate() 
      { 
       //SPWeb currentWeb = SPContext.Current.Web; 

       using (SPSite site = new SPSite(siteId)) 
       { 
        using (SPWeb currentWeb = site.OpenWeb(webId)) 
        { 
         currentWeb.AllowUnsafeUpdates = true; 

         PublishingPage pubPage = PublishingPage.GetPublishingPage(SPContext.Current.ListItem); 
         pubPage.CheckOut(); 

         pubPage.ListItem["EdificioContacto"] = dpEdificio.SelectedValue.ToString(); 
         pubPage.ListItem["ExtensaoContacto"] = txtExtensao.Text; 
         pubPage.ListItem["FaxContacto"] = txtFax.Text; 

         pubPage.Update(); 


         pubPage.ListItem.File.CheckIn("Alteracão de dados de utilizador. Processo automático"); 
         pubPage.ListItem.File.Publish("Alteracão de dados de utilizador. Processo automático"); 
         pubPage.ListItem.File.Approve("Alteracão de dados de utilizador. Processo automático"); 

         currentWeb.AllowUnsafeUpdates = false; 
        } 
       } 

誰能幫助?

編輯:我的例外是「無法評估表達式,因爲代碼已優化或本機框架在調用堆棧之上」。

我以前在另一個類上有過這個例外,但是它是通過使用webId和siteId打開網站和網站來解決的,所以我認爲那樣會解決問題。

編輯2:我注意到,這種情況也發生,當我嘗試以一個「普通」用戶登錄時以編程方式將項目添加到SharePoint列表中。

回答

0

編號:Edit State of page

檢查此代碼段:檢查 'ForceCheckout'

SPListItem item = SPContext.Current.ListItem; 
//we cannot modify the page if we have a current item whos parent list has ForceCheckout set and the items file isn't checked out 
bool canModifyPage = !(item != null && item.File != null && item.ParentList != null && 
item.ParentList.ForceCheckout && item.File.CheckOutStatus == SPFile.SPCheckOutStatus.None); 

可能,這也將幫助你在你的代碼:
Get PageLayout Name in Sharepoint but having a performance issue

編輯:currentWeb.AllowUnsafeUpdates = true;檢查。

編號:PublishingPage.CheckOut Method

// Get the PublishingPage wrapper for the SPListItem that was passed in. 
      // 
      PublishingPage publishingPage = null; 
      if (PublishingPage.IsPublishingPage(listItem)) 
      { 
       publishingPage = PublishingPage.GetPublishingPage(listItem); 
      } 
      else 
      { 
       throw new System.ArgumentException("This SPListItem is not a PublishingPage", "listItem"); 
      } 


      // Check out the page if it is not checked out yet. 
      // 
      if (publishingPage.ListItem.File.CheckOutStatus == SPFile.SPCheckOutStatus.None) 
      { 
       publishingPage.CheckOut(); 
      } 


      // Set and save some properties on the PublishingPage. 
      // 
      publishingPage.Title = newTitle; 
      publishingPage.Description = newDescription; 
      publishingPage.Contact = pageContact; 
      publishingPage.Update(); 

比較它的頁面屬性訪問方法和你..如果有什麼錯在那裏,然後檢查它..

pubPage.ListItem["EdificioContacto"] = dpEdificio.SelectedValue.ToString(); 
pubPage.ListItem["ExtensaoContacto"] = txtExtensao.Text; 
pubPage.ListItem["FaxContacto"] = txtFax.Text; 

希望這有助於..

+0

該布爾返回false。至於第二個鏈接,它沒有發起異常,但是頁面的屬性沒有得到更新。 – user1242471 2012-03-12 16:42:53

+0

嘗試PublishingPage.CheckOut方法文檔示例..可能會解決您的問題。 – 2012-03-13 07:44:33

+0

沒有骰子,條件「publishingPage.ListItem.File.CheckOutStatus == SPFile.SPCheckOutStatus.None」是真的,所以它試圖檢查輸出頁面,但在該指令中拋出異常... – user1242471 2012-03-13 10:38:55

相關問題