473,770 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating virtual directory in IIS using C#

Hello netters,

I was trying to create a virtual directory in IIS using the following
code:
System.Enterpri seServices.Inte rnal.IISVirtual Root vr = new
System.Enterpri seServices.Inte rnal.IISVirtual Root();
string sError;
vr.Create("IIS://localhost/W3SVC/1/Root",@"C:\Prog ram
Files\Soft","We bServices",out sError);
Console.WriteLi ne(sError);
But I am getting following errors:
System.Runtime. InteropServices .COMException (0x80070003): The system
cannot find the path specified
at System.Director yServices.Direc toryEntry.Bind( Boolean throwIfFail)

at System.Director yServices.Direc toryEntry.Bind( )
at System.Director yServices.Direc toryEntry.get_I sContainer()
at System.Director yServices.Direc toryEntries.Che ckIsContainer()
at System.Director yServices.Direc toryEntries.Add (String name, String

schemaClassName )
at System.Enterpri seServices.Inte rnal.IISVirtual Root.Create(Str ing
RootWeb, String inPhysicalDirec tory, String VirtualDirector y,
String&.....
I even tried to create virtual directory using System.Director yEntry.
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 4939
Sample working code I use:
using System;
using System.Director yServices;
namespace PAB.Utils
{
public class MkVdir
{
public MkVdir()
{
}
public static string CreateVDir(stri ng WebSite, string VDirName, string
Path, bool RootDir, bool chkRead,bool chkWrite, bool chkExecute, bool
chkScript, bool chkAuth,int webSiteNum, string serverName)
{
string sRet=String.Emp ty;
System.Director yServices.Direc toryEntry IISSchema;
System.Director yServices.Direc toryEntry IISAdmin;
System.Director yServices.Direc toryEntry VDir;
bool IISUnderNT;
IISSchema = new System.Director yServices.Direc toryEntry("IIS://"
+serverName +"/Schema/AppIsolated");
if (IISSchema.Prop erties["Syntax"].Value.ToString ().ToUpper() ==
"BOOLEAN")
IISUnderNT = true;
else
IISUnderNT = false;
IISAdmin = new
System.Director yServices.Direc toryEntry("IIS://localhost/W3SVC/" + webSiteNum
+ "/Root");
if (!RootDir)
{
foreach(System. DirectoryServic es.DirectoryEnt ry v in IISAdmin.Childr en)
{
if (v.Name == VDirName)
{
// Delete the specified virtual directory if it already exists
try
{
IISAdmin.Invoke ("Delete", new string [] { v.SchemaClassNa me, VDirName
});
IISAdmin.Commit Changes();
}
catch(Exception ex)
{
sRet+=ex.Messag e;
}
}
}
}

//
// Create the virtual directory
//
if (!RootDir)
{
VDir = IISAdmin.Childr en.Add(VDirName , "IIsWebVirtualD ir");
}
else
{
VDir = IISAdmin;
}

//
// Setup the VDir
//
VDir.Properties["AccessRead "][0] = chkRead;
VDir.Properties["AccessExec ute"][0] = chkExecute;
VDir.Properties["AccessWrit e"][0] = chkWrite;
VDir.Properties["AccessScri pt"][0] = chkScript;
VDir.Properties["AuthNTLM"][0] = chkAuth;
VDir.Properties["EnableDefaultD oc"][0] = true;
VDir.Properties["EnableDirBrows ing"][0] = false;
VDir.Properties["DefaultDoc "][0] = true;
VDir.Properties["Path"][0] = Path;
VDir.Properties["AppFriendlyNam e"][0]=VDirName;
//
// NT doesn't support this property
//
if (!IISUnderNT)
{
VDir.Properties["AspEnableParen tPaths"][0] = true;
}
VDir.CommitChan ges();
if (IISUnderNT)
{
VDir.Invoke("Ap pCreate", false);
}
else
{
VDir.Invoke("Ap pCreate", 1);
}
sRet+= "VRoot " +VDirName + " created!";
return sRet;
}
}
}

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


"su*********@ya hoo.com" wrote:
Hello netters,

I was trying to create a virtual directory in IIS using the following
code:
System.Enterpri seServices.Inte rnal.IISVirtual Root vr = new
System.Enterpri seServices.Inte rnal.IISVirtual Root();
string sError;
vr.Create("IIS://localhost/W3SVC/1/Root",@"C:\Prog ram
Files\Soft","We bServices",out sError);
Console.WriteLi ne(sError);
But I am getting following errors:
System.Runtime. InteropServices .COMException (0x80070003): The system
cannot find the path specified
at System.Director yServices.Direc toryEntry.Bind( Boolean throwIfFail)

at System.Director yServices.Direc toryEntry.Bind( )
at System.Director yServices.Direc toryEntry.get_I sContainer()
at System.Director yServices.Direc toryEntries.Che ckIsContainer()
at System.Director yServices.Direc toryEntries.Add (String name, String

schemaClassName )
at System.Enterpri seServices.Inte rnal.IISVirtual Root.Create(Str ing
RootWeb, String inPhysicalDirec tory, String VirtualDirector y,
String&.....
I even tried to create virtual directory using System.Director yEntry.
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
1614
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 Permissions" are set to "Scripts Only" (currently this defaults to "None". Also I want to make the new virtual directory an application (as if I created the virtual directory manually and clicked the "Create Application" button on the vd properties....
0
2281
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 recommended and b) if there is another way. I want to add the projects under the sharepoint site as I want authentication but do not want my users to have to login everytime they access a net app from within the sharepoint site. Ideally, they...
5
3669
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 directory structure: FileManager (application name a.k.a. virtual directory?)
3
1475
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 problems: 1. I am using the code below to create a directory:
7
2397
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 this folder as virtual directory in IIS. I know in ASP how to do it. Set objIIS = GetObject("IIS://localhost/W3SVC/1/Root") objIIS.Create("IISWebVirtualDir", strVirtualDirectoryName)
3
1135
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 figured that part out, I just get lost setting up the "System.DirectoryServices.DirectoryEntry" and then executing the childern.add()
5
3502
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 case. One handle remains open. Debugging shows that it's actually the IIS cache and not ASP.NET that owns this handle. During IIS shutdown, the handle is closed with the following stack trace: ChildEBP RetAddr 0006fbe4 5a403e05...
15
2836
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. Everything is the default settings I believe. IIS is running under Local System. In IIS the DefaultAppPool is running under Network Service. Annonymous access uses the account IUSR_JASMINE (machine name is Jasmine).
1
3372
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 not. It says "Error Creating Control" and then a ton of errors. This occurs both when I use it and in the examples but it does render properly when built. If I drag/drop the control then it shows up properly but when I apply a theme and then...
0
9618
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10101
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.