Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Exchange Web Services .NET
>
Tutorial
> Update folder permission
The following example shows you how to add permission to a folder.
C# example
using System; using System.Net; using Independentsoft.Exchange; namespace Sample { class Program { static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); Service service = new Service("https://myserver/ews/Exchange.asmx", credential); try { Permission permission1 = new Permission(); permission1.UserId = new UserId("Mark@mydomain.com"); permission1.Level = PermissionLevel.Custom; permission1.CanCreateItems = true; permission1.CanCreateSubFolders = true; PermissionSet permissionSet = new PermissionSet(); permissionSet.Permissions.Add(permission1); Property permissionSetProperty = new Property(FolderPropertyPath.PermissionSet, permissionSet); Folder contactsFolder = service.GetFolder(StandardFolder.Contacts); FolderChange change = new FolderChange(contactsFolder.FolderId, permissionSetProperty); service.UpdateFolder(change); } catch (ServiceRequestException ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Error: " + ex.XmlMessage); Console.Read(); } catch (WebException ex) { Console.WriteLine("Error: " + ex.Message); Console.Read(); } } } }
VB example
Imports System Imports System.Net Imports Independentsoft.Exchange Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Dim credential As New NetworkCredential("username", "password") Dim service As New Service("https://myserver/ews/Exchange.asmx", credential) Try Dim permission1 As New Permission() permission1.UserId = New UserId("Mark@mydomain.com") permission1.Level = PermissionLevel.[Custom] permission1.CanCreateItems = True permission1.CanCreateSubFolders = True Dim permissionSet As New PermissionSet() permissionSet.Permissions.Add(permission1) Dim permissionSetProperty As New [Property](FolderPropertyPath.PermissionSet, permissionSet) Dim contactsFolder As Folder = service.GetFolder(StandardFolder.Contacts) Dim change As New FolderChange(contactsFolder.FolderId, permissionSetProperty) service.UpdateFolder(change) Catch ex As ServiceRequestException Console.WriteLine("Error: " + ex.Message) Console.WriteLine("Error: " + ex.XmlMessage) Console.Read() Catch ex As WebException Console.WriteLine("Error: " + ex.Message) Console.Read() End Try End Sub End Class End Namespace
Need help? Ask our developers:
Name*
Email*
Message*