Create Public Folder on Exchange Server

I want to create a public folder on Exchange server and office 365.

I am not getting how to assign permissions using ExchangeFolderPermissionCollection().
Please help me with a sample code.

@ritadcc126,

I have observed your requirements and suggest you to please visit this documentation link for your kind reference for more about adding folders.

public static void CreatePublicFolder(IEWSClient client)
{
NetworkCredential credentials = (NetworkCredential)client.Credentials;
string SMTPaddress = credentials.UserName;
ExchangeFolderPermissionCollection pc = new ExchangeFolderPermissionCollection();
ExchangeFolderUserType userType = ExchangeFolderUserType.Anonymous;
ExchangeFolderUserInfo userInfo = ExchangeFolderUserInfo.AnonymousUser;
userInfo.UserAccountType = userType;
userInfo.PrimarySmtpAddress = SMTPaddress;
ExchangeFolderPermission folderPermission = new ExchangeFolderPermission(userInfo);
folderPermission.CanCreateItems = true;
folderPermission.CanCreateSubFolders = true;
folderPermission.DeleteItems = ExchangeFolderPermissionAction.Owned;
folderPermission.EditItems = ExchangeFolderPermissionAction.Owned;
folderPermission.IsFolderOwner = true;
folderPermission.IsFolderVisible = true;
folderPermission.ReadItems = ExchangeFolderPermissionReadAccess.FullDetails;
folderPermission.UserInfo.PrimarySmtpAddress = SMTPaddress;
folderPermission.IsFolderContact = true;
folderPermission.PermissionLevel = ExchangeFolderPermissionLevel.Owner;
pc.Add(folderPermission);
string publicfolderUri= client.CreatePublicFolder(“ABC”, pc).Uri;
MessageBox.Show("Folder ABC Created @ "+SMTPaddress);
}

This is my piece of code to create public folder in admin account but I am getting following error.
/*An unhandled exception of type ‘Aspose.Email.AsposeInvalidOperationException’ occurred in Aspose.Email.dll

Additional information: Creation folder failed.Response Code: ErrorAccessDenied, MessageText: Access is denied.Check credentials and try again., Could not create folder ABC.
*/
How can I correct the above code ? Please suggest me on this.

@ritadcc126,

I have observed the code provided and request you to please provide the sample test account that we may use on our end to verify and help you further.