I have a created A browser enabled form it has two fields. I want to use the SharePoint object model.
I have added the SharePoint dll to the project and also include the using Microsoft.Sharepoint statement.
   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.
    }
}
} `
When i click on the button i get the following error.
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)
Under the Forms options-> Security and trust -> Full trust.
Please can anyone suggest if  I need to do anything else.
 
                        
I am also facing the same issue in my code. I have did the following and the issue has resolved. Please try the below and let me know whether it is solved the issue or not.
File > Info > Design Checker > Open the Design Checker Window. In that, click Change Settings > Security and Trust > Choose the option Full Trust.