Posts Tagged InfoPath 2007

SecurityException was unhandled by user code – VSTA, C#, InfoPath 2007

I got this error, while I was developing a InfoPath form in VSTA (Visual Studio Tools for Applications 2008) . This was my enviornment:

  • Windows 7
  • VSTA 2008
  • InfoPath 2007

Scenario: I was trying to get the user information from Active Directory(AD) and then display in an InfoPath form. Here is the C# code I have written in the VSTA:

public void CTRL1_5_Clicked(object sender, ClickedEventArgs e)
 {
 string strUserName = System.Environment.UserName;

 string xpath2 = "/my:myFields/my:field1";
 XPathNavigator field2 = MainDataSource.CreateNavigator().SelectSingleNode(xpath2, NamespaceManager);
 field2.SetValue(GetOU(strUserName)); //Get Organization Unit(OU) from Acitve Directory(AD)
 }

This is the error message I have got: 😦

Solution: I have fixed this issue in a different situation, just read in my previous post.

Thanks. R./

Happy InfoPathing. 🙂

Advertisement

, , , ,

1 Comment

InfoPath cannot grant access to these files and settings because the form template is not fully trusted. For a form to run with full trust, it must be installed or digitally signed with a certificate – InfoPath 2007 forms Security Levels

After giving the Full Trust to the Form template (See here), we will be able to preview the InfoPath form and get information from other domains, or access files and settings on a user’s computer. But when we publish InfoPath form on SharePoint and try to access the from then you will be getting this error. 😦

Error:

Details:

Text format of the error:

Form template: file:///C:\Documents%20and%20Settings\RajanihanthV\Desktop\XmlProc\InfoPath\ADInfo.xsn</pre>
The form template is trying to access files and settings on your computer. InfoPath cannot grant access to these files and settings because the form template is not fully trusted. For a form to run with full trust, it must be installed or digitally signed with a certificate.

If we need to access the form from SharePoint, we need to be digitally signed the form even it is fully trusted. This is pretty simple, but we have to do this process after publishing the form on SharePoint only. Here are the steps.

Step 1: Navigate to the Document (form) Library, where your form published

Step 2: Click Settings on the Document Library Settings

Step 3: Advanced Settings

Step 4: Edit Template

Step 5: Click the Form Options on the Tools menu

Step 6: Click Sign this Form Template and create or select certificate, then OK

That’s all. You can try and see. 🙂

This will work only for you (author), If you want give access to all users you have to get the digital signature from 3rd party vendors and signed the form.

Thanks. R./

, , , ,

4 Comments

Request for the permission of type ‘System.DirectoryServices.DirectoryServicesPermission, System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ failed – InfoPath 2007 forms Security Levels

When I was trying to display user information from Active Directory(AD) in an InfoPath form, I have got an error message saying that I don’t have permissions to access the Directory services. 😦

Details of the error message:

Text format of the error:

System.Security.SecurityException
 Request for the permission of type 'System.DirectoryServices.DirectoryServicesPermission, System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' failed.
at Template2.FormCode.GetOU(String username)
at Template2.FormCode.CTRL1_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)

I have faced this kind of security level errors while creating a web parts using Active Directory(AD) and you can read this in my previous post.

Basically InfoPath provides three security levels for forms, they are:

  • Restricted
  • Domain
  • Full Trust

The security levels determine whether a form can access data on other domains, or access files and settings on a user’s computer. If you need more info about this, just click here.

When we design/create an InfoPath form, the minimum trust level will be assigned in-default and which is not enough to access the Directory Services. So we need to change the trust level to access the information.  These are the simple steps to change the Trust Levels in InfoPath,

Step 1: Open the Form template in Design Mode

Step 2: Click the Form Options on the Tools menu

Step 3: You will be getting the following window and the security levels automatically determined

Step 4: Unchecked the check box, give the permissions to ‘Full Trust’ and then click OK

That’s all, you can access the Directory Services programmatically and display in your InfoPath form.  Sometimes you will be getting another error after fixing this (probably after publishing to SharePoint), to solve this problem we just need to specify the digitally signed certificate for this form. Check out the error message here.

Thanks. R./

, , , , , , ,

2 Comments