Click here to Skip to main content
15,879,326 members
Articles / Programming Languages / C#

Setting Exchange Folder Permissions Remotely

Rate me:
Please Sign up or sign in to vote.
4.90/5 (27 votes)
3 Feb 20058 min read 66.8K   1.8K   33  
A way to remotely set permissions on folders in the Exchange Server using an Exchange SDK-based COM in-proc wrapped into a .NET class and exposed to a client with Remoting technique.
using System;
using System.Threading;

//REMOTING
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

using SrvInterface;

namespace Client
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class Class1
	{
		const string strSrvHostURI = "http://ccDevEx:8961/ClientPermission";
		static IClientPermission permission = null;

		const string strO  = "First Organization";
		const string strOU = "First Administrative Group";

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			Console.WriteLine("Client started...");

			HttpClientChannel httpChannel = new HttpClientChannel();
			ChannelServices.RegisterChannel(httpChannel);
			permission = (IClientPermission)Activator.GetObject(typeof(IClientPermission), strSrvHostURI);
			
			// Start the second thread
			Thread td = new Thread(new ThreadStart(ThreadProc));
			td.Start();

			permission.Add("aaa", "userAAA", (int)Permissions.RoleContributor, strO, strOU);
			permission.Add("aaa", "userBBB", (int)Permissions.RoleContributor, null, null);
			permission.Modify("aaa", "userAAA", (int)Permissions.RolePublishAuthor);
			
			// Wait for the second thread joining
			td.Join();

			Console.WriteLine("\nPress Enter to exit...");
			Console.ReadLine();
		}

		static void ThreadProc()
		{
			permission.Add("bbb", "userAAA", (int)Permissions.RoleContributor, null, null);
			permission.Add("bbb", "userBBB", (int)Permissions.RoleContributor, strO, strOU);
			permission.Modify("bbb", "userBBB", (int)Permissions.RolePublishAuthor);
			permission.Remove("bbb", "userAAA");
			permission.Modify("bbb", "userBBB", (int)Permissions.RoleNone - (int)Permissions.RightsFolderVisible);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Israel Israel


  • Nov 2010: Code Project Contests - Windows Azure Apps - Winner
  • Feb 2011: Code Project Contests - Windows Azure Apps - Grand Prize Winner



Comments and Discussions