Click here to Skip to main content
15,891,976 members
Articles / Web Development / IIS

DotNetNuke Module Packager

Rate me:
Please Sign up or sign in to vote.
4.67/5 (13 votes)
21 Oct 200523 min read 162.5K   1.8K   82  
This article describes the DotNetNuke Module Packager application and source code. The application enables the user to generate DotNetNuke private assemblies that are useable out of the box from a custom module defined in the programmer's development environment.
//////////////////////////////////////////////////////////////////////////
// DNN Module Packager 1.0
// Copyright (C) 2004-2005 Matt Long
// 
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// 
// You can contact the author at: matt.long@matthew-long.com
//
//////////////////////////////////////////////////////////////////////////


using System;
using System.DirectoryServices;
using System.Collections;

namespace SkyeRoad.DNNTools
{
	/// <summary>
	/// Summary description for VirtualDirectoryUtility.
	/// </summary>
	public class VirtualDirectoryUtility
	{

		public VirtualDirectoryUtility()
		{
		}

		public Hashtable GetSitePaths()
		{
			Hashtable tmp = new Hashtable();
			DirectoryEntry root = new DirectoryEntry("IIS://localhost/w3svc/1/root");
			foreach( DirectoryEntry e in root.Children )
			{
				tmp[ e.Name ] = e.Path;
			}

			return tmp;
		}

		public string GetVirtualDirLocalPath( string directoryEntry )
		{
			DirectoryEntry virtualPath = new DirectoryEntry( directoryEntry );
			return virtualPath.Properties["Path"].Value.ToString();
		}

		public int CreateWebSite(string webSiteName, string pathToRoot)
		{

			return CreateWebSite(webSiteName, pathToRoot, false);

		}

		public int CreateWebSite(string webSiteName, string pathToRoot, bool createDir)
		{
			string entryRoot = "IIS://localhost/W3SVC";
			DirectoryEntry root = new DirectoryEntry(entryRoot);

			// Find unused ID value for new web site
			int siteID = 1;
			foreach(DirectoryEntry e in root.Children)
			{
				if(e.SchemaClassName == "IIsWebServer")
				{
					int ID = Convert.ToInt32(e.Name);
					if(ID >= siteID)
					{
						siteID = ID+1;
					}
				}
			}

			// Create web site
			DirectoryEntry site = (DirectoryEntry)root.Invoke("Create", "IIsWebServer", siteID);
			site.Invoke("Put", "ServerComment", webSiteName);
			site.Invoke("Put", "KeyType", "IIsWebServer");
			site.Invoke("Put", "ServerBindings", ":80:");
			site.Invoke("Put", "ServerState", 2);
			site.Invoke("Put", "FrontPageWeb", 1);
			site.Invoke("Put", "DefaultDoc", "Default.aspx");
			site.Invoke("Put", "SecureBindings", ":443:");
			site.Invoke("Put", "ServerAutoStart", 1);
			site.Invoke("Put", "ServerSize", 1);
			site.Invoke("SetInfo");

			// Create application virtual directory
			DirectoryEntry siteVDir = site.Children.Add("Root", "IISWebVirtualDir");
			siteVDir.Properties["AppIsolated"][0] = 2;
			siteVDir.Properties["Path"][0] = pathToRoot;
			siteVDir.Properties["AccessFlags"][0] = 513;
			siteVDir.Properties["FrontPageWeb"][0] = 1;
			siteVDir.Properties["AppRoot"][0] = "/LM/W3SVC/"+siteID+"/Root";
			siteVDir.Properties["AppFriendlyName"][0] = "Root";
			siteVDir.CommitChanges();
			site.CommitChanges();

			return siteID;

		}

	}
}

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
Web Developer
United States United States
Matt Long is the Director of Technology for Skye Road Systems, Inc. in Colorado Springs, Colorado. He provides software architecture consulting services to small businesses. To contact Matt ( perlmunger ) send an email to matt@skyeroadsystems.com.

Comments and Discussions