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=220.127.116.11, 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:
- 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.