473,397 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Creating virtual directory in IIS using C#

Hello netters,

I was trying to create a virtual directory in IIS using the following
code:
System.EnterpriseServices.Internal.IISVirtualRoot vr = new
System.EnterpriseServices.Internal.IISVirtualRoot( );
string sError;
vr.Create("IIS://localhost/W3SVC/1/Root",@"C:\Program
Files\Soft","WebServices",out sError);
Console.WriteLine(sError);
But I am getting following errors:
System.Runtime.InteropServices.COMException (0x80070003): The system
cannot find the path specified
at System.DirectoryServices.DirectoryEntry.Bind(Boole an throwIfFail)

at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsCont ainer()
at System.DirectoryServices.DirectoryEntries.CheckIsC ontainer()
at System.DirectoryServices.DirectoryEntries.Add(Stri ng name, String

schemaClassName)
at System.EnterpriseServices.Internal.IISVirtualRoot. Create(String
RootWeb, String inPhysicalDirectory, String VirtualDirectory,
String&.....
I even tried to create virtual directory using System.DirectoryEntry.
It gives me the same error.
Iam sure C:\Program Files\Soft exists . I am doubtful if Iam making
some mistake in passing first parameter.
Can Somebody please tell me what is going wrong?
Thanking you in advance,
Sudha

May 26 '06 #1
1 4904
Sample working code I use:
using System;
using System.DirectoryServices;
namespace PAB.Utils
{
public class MkVdir
{
public MkVdir()
{
}
public static string CreateVDir(string WebSite, string VDirName, string
Path, bool RootDir, bool chkRead,bool chkWrite, bool chkExecute, bool
chkScript, bool chkAuth,int webSiteNum, string serverName)
{
string sRet=String.Empty;
System.DirectoryServices.DirectoryEntry IISSchema;
System.DirectoryServices.DirectoryEntry IISAdmin;
System.DirectoryServices.DirectoryEntry VDir;
bool IISUnderNT;
IISSchema = new System.DirectoryServices.DirectoryEntry("IIS://"
+serverName +"/Schema/AppIsolated");
if (IISSchema.Properties["Syntax"].Value.ToString().ToUpper() ==
"BOOLEAN")
IISUnderNT = true;
else
IISUnderNT = false;
IISAdmin = new
System.DirectoryServices.DirectoryEntry("IIS://localhost/W3SVC/" + webSiteNum
+ "/Root");
if (!RootDir)
{
foreach(System.DirectoryServices.DirectoryEntry v in IISAdmin.Children)
{
if (v.Name == VDirName)
{
// Delete the specified virtual directory if it already exists
try
{
IISAdmin.Invoke("Delete", new string [] { v.SchemaClassName, VDirName
});
IISAdmin.CommitChanges();
}
catch(Exception ex)
{
sRet+=ex.Message;
}
}
}
}

//
// Create the virtual directory
//
if (!RootDir)
{
VDir = IISAdmin.Children.Add(VDirName, "IIsWebVirtualDir");
}
else
{
VDir = IISAdmin;
}

//
// Setup the VDir
//
VDir.Properties["AccessRead"][0] = chkRead;
VDir.Properties["AccessExecute"][0] = chkExecute;
VDir.Properties["AccessWrite"][0] = chkWrite;
VDir.Properties["AccessScript"][0] = chkScript;
VDir.Properties["AuthNTLM"][0] = chkAuth;
VDir.Properties["EnableDefaultDoc"][0] = true;
VDir.Properties["EnableDirBrowsing"][0] = false;
VDir.Properties["DefaultDoc"][0] = true;
VDir.Properties["Path"][0] = Path;
VDir.Properties["AppFriendlyName"][0]=VDirName;
//
// NT doesn't support this property
//
if (!IISUnderNT)
{
VDir.Properties["AspEnableParentPaths"][0] = true;
}
VDir.CommitChanges();
if (IISUnderNT)
{
VDir.Invoke("AppCreate", false);
}
else
{
VDir.Invoke("AppCreate", 1);
}
sRet+= "VRoot " +VDirName + " created!";
return sRet;
}
}
}

--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"su*********@yahoo.com" wrote:
Hello netters,

I was trying to create a virtual directory in IIS using the following
code:
System.EnterpriseServices.Internal.IISVirtualRoot vr = new
System.EnterpriseServices.Internal.IISVirtualRoot( );
string sError;
vr.Create("IIS://localhost/W3SVC/1/Root",@"C:\Program
Files\Soft","WebServices",out sError);
Console.WriteLine(sError);
But I am getting following errors:
System.Runtime.InteropServices.COMException (0x80070003): The system
cannot find the path specified
at System.DirectoryServices.DirectoryEntry.Bind(Boole an throwIfFail)

at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsCont ainer()
at System.DirectoryServices.DirectoryEntries.CheckIsC ontainer()
at System.DirectoryServices.DirectoryEntries.Add(Stri ng name, String

schemaClassName)
at System.EnterpriseServices.Internal.IISVirtualRoot. Create(String
RootWeb, String inPhysicalDirectory, String VirtualDirectory,
String&.....
I even tried to create virtual directory using System.DirectoryEntry.
It gives me the same error.
Iam sure C:\Program Files\Soft exists . I am doubtful if Iam making
some mistake in passing first parameter.
Can Somebody please tell me what is going wrong?
Thanking you in advance,
Sudha

May 26 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JDeats | last post by:
I have a function that creates a new Virtual Directory. I would like to alter this function so that it sets a few properties on this new virtual directory, namely I want to make it so "Execute...
0
by: Ken Wigle | last post by:
All, I am trying to add some .net applications I wrote to a virtual directory underneath the sharepoint services web site. I am having some problems and wondering if a) this is possible and/or...
5
by: Leszek | last post by:
Hello, Could anybody explain what's a difference between a virtual directory and an application root under IIS? I'm a little bit confused. This is mu problem: Let's assume the following...
3
by: Stelrad Doulton | last post by:
Hi, I am having a strange problem on IIS 6.0. I am trying to create directories under a virtual directory on the fly to which I will upload files and retrieve these files later. I am having 2...
7
by: Jaydeep | last post by:
Hi, Anybody knows how to create virtual directory programmatically under root directory ofcourse from code-behind. I am developing web-based application where I need to create a folder and making...
3
by: Microsoft | last post by:
I have a web site called www.test.com I have a folder under the wwwroot called \testfolder\ How do I turn \testfolder\ into a virtual directory. I don't need rights and settings, I've...
5
by: Sam777 | last post by:
I was under the impression that creating the app_offline.htm file at the root of the webapp would cause all handles to be closed so that the app could be removed. Unfortunately, this isn't the...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
1
by: Light | last post by:
Re, I'm having 2 problems with the Telerik trial controls. I'm using the latest release. I'm using 2005 studio and most of the controls show up properly in the designer but the RadMenu does...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.