Edit

Share via


Permission.Add(String, Object, Object) Method

Definition

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

public:
 Microsoft::Office::Interop::InfoPath::SemiTrust::UserPermissionObject ^ Add(System::String ^ bstrUserId, System::Object ^ varPermission, System::Object ^ varExpirationDate);
public Microsoft.Office.Interop.InfoPath.SemiTrust.UserPermissionObject Add (string bstrUserId, object varPermission, object varExpirationDate);
abstract member Add : string * obj * obj -> Microsoft.Office.Interop.InfoPath.SemiTrust.UserPermissionObject
Public Function Add (bstrUserId As String, varPermission As Object, varExpirationDate As Object) As UserPermissionObject

Parameters

bstrUserId
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
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
Object

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

Returns

A UserPermissionObject that represents the specified user.

Examples

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);
Dim thisDoc As _XDocument3 = DirectCast(thisXDocument, _XDocument3)

Dim strExpirationDate As String = _
   DateTime.Today.AddDays(2).ToString()
dtExpirationDate As DateTime = DateTime.Parse(strExpirationDate)

thisDoc.Permission.UserPermissions.Add("someone@example.com", _
   msoPermission.msoPermissionFullControl, dtExpirationDate)

Remarks

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 Object Model 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.

Applies to