Export (0) Print
Expand All

Permission.Add method

Creates a new set of permissions on the current form for the specified user with the specified permissions and an expiration date.

Namespace:  Microsoft.Office.Interop.InfoPath.SemiTrust
Assembly:  Microsoft.Office.Interop.InfoPath.SemiTrust (in Microsoft.Office.Interop.InfoPath.SemiTrust.dll)

UserPermissionObject Add(
	string bstrUserId,
	Object varPermission,
	Object varExpirationDate
)

Parameters

bstrUserId
Type: System.String

The e-mail address in the format user@domain.com of the user to whom permissions on the current form are being granted. Required.

varPermission
Type: System.Object

The permissions on the current form that are being granted to the specified user as a combination of one or more MsoPermission values. Optional.

varExpirationDate
Type: System.Object

The expiration date for the permissions that are being granted as a System.DateTime value. Optional.

Return value

Type: Microsoft.Office.Interop.InfoPath.SemiTrust.UserPermissionObject
A UserPermissionObject that represents the specified user.

To access the MsoPermission enumeration values for setting the varPermission parameter, you must set a reference to the Microsoft Office 14.0 Object Library using COM tab of the Add Reference dialog box in Visual Studio 2012 or Visual Studio. This will establish a reference to the members of the Microsoft.Office.Core namespace.

Because the Permission object and its members are new to Microsoft InfoPath, you must cast the object returned by the thisXDocument variable to the _XDocument3 type to access this object and its members. For more information, see How to: Use Microsoft.Office.Interop.InfoPath.SemiTrust Members That Are Not Compatible with InfoPath 2003.

This member can be accessed only by forms opened from a form template that has been configured to run with full trust using the Security and Trust category of the Form Options dialog box. This member requires full trust for the immediate caller and cannot be used by partially trusted code. For more information, see "Using Libraries from Partially Trusted Code" on MSDN.

In the following example, the Add method is used to add a new user to the form, assign that user to the Full Control access level, and set an expiration date of two days from the current date.

This example requires a using or Imports directive for the Microsoft.Office.Core namespace in the declarations section of the form module.

_XDocument3 thisDoc = (_XDocument3)thisXDocument;

string strExpirationDate = DateTime.Today.AddDays(2).ToString();
DateTime dtExpirationDate = DateTime.Parse(strExpirationDate);

thisDoc.Permission.Add("someone@example.com",
   msoPermission.msoPermissionFullControl, dtExpirationDate);
Show:
© 2014 Microsoft