2012-03-12 55 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

相关问题