2013-08-24 66 views
0

」的權限我已創建一個啓用了A瀏覽器的窗體,它有兩個字段。我想要使​​用SharePoint對象模型。System.Security.SecurityException請求類型爲「Microsoft.SharePoint.Security.SharePointPermission

我已經將SharePoint dll添加到項目中,並且還包括使用Microsoft.Sharepoint語句。

using Microsoft.Office.InfoPath; 
using System; 
using System.Xml; 
using System.Xml.XPath; 
using Microsoft.SharePoint; 

namespace test1 
{ 
    public partial class FormCode 
    { 

    public void InternalStartup() 
    { 
     ((ButtonEvent)EventManager.ControlEvents["CTRL2_5"]).Clicked += new ClickedEventHandler(CTRL2_5_Clicked); 
    } 

    public void CTRL2_5_Clicked(object sender, ClickedEventArgs e) 

    { 
     string url = "http://site"; 
     using (SPSite site = new SPSite(url)) 
     { 

      using (SPWeb web = site.OpenWeb()) 
      { 
       XPathNavigator nav = MainDataSource.CreateNavigator(); 
       nav.SelectSingleNode("/my:myFields/my:field1", NamespaceManager).SetValue(web.Title.to nav.SelectSingleNode("/my:myFields/my:field2",NamespaceManager).Value.ToString()); 
      } 
     } 
     // Write your code here. 
    } 
} 

} `

當我按一下按鈕我碰到下面的錯誤。

System.Security.SecurityException 
Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed. 
    at test1.FormCode.CTRL2_5_Clicked(Object sender, ClickedEventArgs e) 
    at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent) 
    at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent) 

根據表格選項 - >安全性和信任 - >完全信任。

Please can anyone suggest if I need to do anything else. 

回答

1

我在我的代碼中也面臨同樣的問題。我做了以下事情,問題已解決。請嘗試下面的內容,讓我知道它是否解決了問題。

File> Info> Design Checker>打開Design Checker窗口。在此,單擊更改設置>安全和信任>選擇完全信任選項。

+0

這個解決方案也解決了我的問題。 – mohsenof