469,568 Members | 1,520 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

How to Create a Virtual Directory using C#?

Hello,

I need to create a Virtual Directory in C#.

Pls let me know if you have any hints regarding this..

Thanks,
Smitha
Nov 17 '05 #1
3 1980
What do u exactly mean by Virtual directory?

"Smitha Nataraj" <sm************@in.bosch.com> wrote in message
news:dh**********@ns2.fe.internet.bosch.com...
Hello,

I need to create a Virtual Directory in C#.

Pls let me know if you have any hints regarding this..

Thanks,
Smitha

Nov 17 '05 #2

I need to create a Virtual directory in IIS i.e. I need to create a web
application on the IIS server from my .NET application.

This can be done using DirectoryServices in .NET. But I am facing some
problems. The directory entry is done but I cannot see it in IIS manager nor
does the application exist. But, if we try to create it again with the same
name, it says already exists.

Pls let me know if you have any hint...

Thanks!
Smitha

"Gnanaprakash Rathinam" <gn*******************@oracle.com> wrote in message
news:j6**************@news.oracle.com...
What do u exactly mean by Virtual directory?

"Smitha Nataraj" <sm************@in.bosch.com> wrote in message
news:dh**********@ns2.fe.internet.bosch.com...
Hello,

I need to create a Virtual Directory in C#.

Pls let me know if you have any hints regarding this..

Thanks,
Smitha


Nov 17 '05 #3
I used this in the past...
/// <summary>
/// Create a new Virtual Directory within IIS
/// </summary>
/// <param name="ServerId">The ID of the Server within IIS</param>
/// <param name="VirtualDirName">IIS Name of the new Virtual Directory</param>
/// <param name="Path">Physical Path to the new Virtual Directory</param>
/// <param name="AccessScript"></param>
/// <param name="CreatePhysicalFolder">Create the folder on the file system</param>
public static bool CreateNewVirtualDirectory(int ServerId, string VirtualDirName, string Path, bool AccessScript, bool CreatePhysicalFolder)
{
DirectoryEntry Parent = new DirectoryEntry(@"IIS://localhost/W3SVC/" + ServerId.ToString() + "/Root");
DirectoryEntry NewVirtualDir;
NewVirtualDir = Parent.Children.Add(VirtualDirName, "IIsWebVirtualDir");
NewVirtualDir.Properties["Path"][0] = Path;
NewVirtualDir.Properties["AccessScript"][0] = AccessScript;
NewVirtualDir.Properties["AppFriendlyName"][0] = VirtualDirName;
NewVirtualDir.Properties["AppPoolId"][0] = "DefaultAppPool";
NewVirtualDir.Properties["AppRoot"][0] = "/LM/W3SVC/" + ServerId.ToString() + "/Root/" + VirtualDirName;
NewVirtualDir.Properties["AppIsolated"][0] = 2;
NewVirtualDir.CommitChanges();
if(CreatePhysicalFolder)
{
if(!Directory.Exists(Path))
{
Directory.CreateDirectory(Path);
return true;
}
}
else
{
return true;
}
return true;
}


(Error checking / catching has been stripped from this example...)
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by No Spam | last post: by
2 posts views Thread by Siegfried Heintze | last post: by
4 posts views Thread by Mark | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.