473,607 Members | 2,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# and Virtual Directory

Hi all,
If I need to make a C# application, do I need to set up a virtual dir such
as inetroot on the Harddisks. How do I set up such thingy?
Thanks
Jack
Nov 15 '05 #1
2 14418
Using the System.Director yServices namespace classes.
Herewith something (not tested) to get you started...

Willy.

using System;
using System.Director yServices;
using System.IO;
class IISVdir {
// Authorization flags
const int MD_AUTH_ANONYMO US = 0x00000001; //Anonymous authentication
available.
const int MD_AUTH_BASIC = 0x00000002; //Basic authentication available.
const int MD_AUTH_NT = 0x00000004; //Windows authentication schemes
available.
// Browse flags
const int MD_DIRBROW_SHOW _DATE = 0x00000002; //Show date.
const int MD_DIRBROW_SHOW _TIME = 0x00000004; // Show time.
const int MD_DIRBROW_SHOW _SIZE = 0x00000008; //Show file size.
const int MD_DIRBROW_SHOW _EXTENSION = 0x00000010; //Show file name
extension.
const int MD_DIRBROW_LONG _DATE = 0x00000020; //Show full date.
const int MD_DIRBROW_LOAD DEFAULT = 0x40000000; // Load default page, if it
exists.
const uint MD_DIRBROW_ENAB LED = 0x80000000;
// Access Flags
const int MD_ACCESS_READ = 0x00000001; //Allow read access.
const int MD_ACCESS_WRITE = 0x00000002; //Allow write access.
const int MD_ACCESS_EXECU TE = 0x00000004; //Allow file execution
(includes script permission).
const int MD_ACCESS_SOURC E = 0x00000010; //Allow source access.
const int MD_ACCESS_SCRIP T = 0x00000200; // Allow script execution.
const int MD_ACCESS_NO_RE MOTE_WRITE = 0x00000400; // Local write access
only.
const int MD_ACCESS_NO_RE MOTE_READ = 0x00001000; // Local read access
only.
const int MD_ACCESS_NO_RE MOTE_EXECUTE = 0x00002000; // Local execution
only.
const int MD_ACCESS_NO_RE MOTE_SCRIPT = 0x00004000; // Local host access
only.

public static void Main() {
// Create a virtual directory and application in the IIS Root
CreateVirtualDi rectory("IIS://localhost/W3SVC/1/Root", "someWeb",
"c:\\somefolder ");
}

public static void CreateVirtualDi rectory(string parent, string
virtDirectory, string physicalDir)
{
// Delete VDir if already exists
if(CheckIfExist s(parent, virtDirectory))
{
Delete(parent, virtDirectory, physicalDir);
}
// Create physical directory if non existent
if (!Directory.Exi sts(physicalDir ))
{
Directory.Creat eDirectory(phys icalDir);
}
// remove / or \\ at end of path if any
string str = physicalDir;
if (physicalDir.En dsWith("/") || physicalDir.End sWith("\\"))
{
str = physicalDir.Rem ove(physicalDir .Length - 1, 1);
}
DirectoryEntry folderRoot = new DirectoryEntry( parent);
folderRoot.Refr eshCache();

DirectoryEntry vDir =
folderRoot.Chil dren.Add(virtDi rectory,"IIsWeb VirtualDir");
vDir.CommitChan ges();
// Set Properties
vDir.Properties["Path"].Value =str;
vDir.Properties["AuthFlags"].Value = MD_AUTH_ANONYMO US | MD_AUTH_NT;
vDir.Properties["DefaultDoc "].Value = "default.as px";
vDir.Properties["DirBrowseFlags "].Value = MD_DIRBROW_SHOW _DATE |
MD_DIRBROW_ENAB LED |
MD_DIRBROW_SHOW _SIZE | MD_DIRBROW_SHOW _EXTENSION |
MD_DIRBROW_LONG _DATE | MD_DIRBROW_LOAD DEFAULT;
vDir.Properties["AccessFlag s"].Value = MD_ACCESS_READ |
MD_ACCESS_SCRIP T;
// add a custom header, format is (key: value)
object[] headers = {"TestValue: 1", "AnotherOne : 1234"};
vDir.Properties["HttpCustomHead ers"].AddRange(heade rs);
// Call AppCreat2 to create a Web application (0 =In-proc, 1 =
Out-proc, 2 = Pooled) , required by IIS, not used by ASP.NET
object[] applicationType = new object[]{0};
vDir.Invoke("Ap pCreate2", applicationType );
// Save Changes
vDir.CommitChan ges();
folderRoot.Comm itChanges();
vDir.Close();
folderRoot.Clos e();
}

internal static bool CheckIfExists(s tring RootWeb, string VirtualDirector y)
{
DirectoryEntry directoryEntry = new DirectoryEntry( String.Concat(R ootWeb,
"/", VirtualDirector y));
try
{
string name = directoryEntry. Name;
return true;
}
catch
{
bool flag = false;
return flag;
}
}

internal static void Delete(string RootWeb, string VirtualDirector y, string
PhysicalDirecto ry)
{
try
{
DirectoryEntry root = new DirectoryEntry( RootWeb);
DirectoryEntry vdir = root.Children.F ind(VirtualDire ctory,
root.SchemaClas sName);
// Remove Entry from container.
string strName = vdir.Name;
root.Children.R emove(vdir);
Console.WriteLi ne(strName+ " entry is removed from container.");
root.CommitChan ges();
root.Close();
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}
// delete physical dir
Directory.Delet e(PhysicalDirec tory, true);
}
}


"Jacky Luk" <no****@nospam. com> wrote in message
news:uY******** ******@TK2MSFTN GP11.phx.gbl...
Hi all,
If I need to make a C# application, do I need to set up a virtual dir such
as inetroot on the Harddisks. How do I set up such thingy?
Thanks
Jack

Nov 15 '05 #2
Thanks and it's really nice info :). I had another question, when I
opened/created a C# web service or web application.. It didn't allow me to
do so, it just prompt me to open a virtual directory. In the case, do I
artifically create inetroot on the C Drive?
Thanks in advance
Jack

"Willy Denoyette [MVP]" <wi************ *@pandora.be> ¼¶¼g©ó¶l¥ó·s»D
:uV************ *@tk2msftngp13. phx.gbl...
Using the System.Director yServices namespace classes.
Herewith something (not tested) to get you started...

Willy.

using System;
using System.Director yServices;
using System.IO;
class IISVdir {
// Authorization flags
const int MD_AUTH_ANONYMO US = 0x00000001; //Anonymous authentication
available.
const int MD_AUTH_BASIC = 0x00000002; //Basic authentication available.
const int MD_AUTH_NT = 0x00000004; //Windows authentication schemes
available.
// Browse flags
const int MD_DIRBROW_SHOW _DATE = 0x00000002; //Show date.
const int MD_DIRBROW_SHOW _TIME = 0x00000004; // Show time.
const int MD_DIRBROW_SHOW _SIZE = 0x00000008; //Show file size.
const int MD_DIRBROW_SHOW _EXTENSION = 0x00000010; //Show file name
extension.
const int MD_DIRBROW_LONG _DATE = 0x00000020; //Show full date.
const int MD_DIRBROW_LOAD DEFAULT = 0x40000000; // Load default page, if it exists.
const uint MD_DIRBROW_ENAB LED = 0x80000000;
// Access Flags
const int MD_ACCESS_READ = 0x00000001; //Allow read access.
const int MD_ACCESS_WRITE = 0x00000002; //Allow write access.
const int MD_ACCESS_EXECU TE = 0x00000004; //Allow file execution
(includes script permission).
const int MD_ACCESS_SOURC E = 0x00000010; //Allow source access.
const int MD_ACCESS_SCRIP T = 0x00000200; // Allow script execution.
const int MD_ACCESS_NO_RE MOTE_WRITE = 0x00000400; // Local write access
only.
const int MD_ACCESS_NO_RE MOTE_READ = 0x00001000; // Local read access
only.
const int MD_ACCESS_NO_RE MOTE_EXECUTE = 0x00002000; // Local execution
only.
const int MD_ACCESS_NO_RE MOTE_SCRIPT = 0x00004000; // Local host access
only.

public static void Main() {
// Create a virtual directory and application in the IIS Root
CreateVirtualDi rectory("IIS://localhost/W3SVC/1/Root", "someWeb",
"c:\\somefolder ");
}

public static void CreateVirtualDi rectory(string parent, string
virtDirectory, string physicalDir)
{
// Delete VDir if already exists
if(CheckIfExist s(parent, virtDirectory))
{
Delete(parent, virtDirectory, physicalDir);
}
// Create physical directory if non existent
if (!Directory.Exi sts(physicalDir ))
{
Directory.Creat eDirectory(phys icalDir);
}
// remove / or \\ at end of path if any
string str = physicalDir;
if (physicalDir.En dsWith("/") || physicalDir.End sWith("\\"))
{
str = physicalDir.Rem ove(physicalDir .Length - 1, 1);
}
DirectoryEntry folderRoot = new DirectoryEntry( parent);
folderRoot.Refr eshCache();

DirectoryEntry vDir =
folderRoot.Chil dren.Add(virtDi rectory,"IIsWeb VirtualDir");
vDir.CommitChan ges();
// Set Properties
vDir.Properties["Path"].Value =str;
vDir.Properties["AuthFlags"].Value = MD_AUTH_ANONYMO US | MD_AUTH_NT;
vDir.Properties["DefaultDoc "].Value = "default.as px";
vDir.Properties["DirBrowseFlags "].Value = MD_DIRBROW_SHOW _DATE |
MD_DIRBROW_ENAB LED |
MD_DIRBROW_SHOW _SIZE | MD_DIRBROW_SHOW _EXTENSION |
MD_DIRBROW_LONG _DATE | MD_DIRBROW_LOAD DEFAULT;
vDir.Properties["AccessFlag s"].Value = MD_ACCESS_READ |
MD_ACCESS_SCRIP T;
// add a custom header, format is (key: value)
object[] headers = {"TestValue: 1", "AnotherOne : 1234"};
vDir.Properties["HttpCustomHead ers"].AddRange(heade rs);
// Call AppCreat2 to create a Web application (0 =In-proc, 1 =
Out-proc, 2 = Pooled) , required by IIS, not used by ASP.NET
object[] applicationType = new object[]{0};
vDir.Invoke("Ap pCreate2", applicationType );
// Save Changes
vDir.CommitChan ges();
folderRoot.Comm itChanges();
vDir.Close();
folderRoot.Clos e();
}

internal static bool CheckIfExists(s tring RootWeb, string VirtualDirector y) {
DirectoryEntry directoryEntry = new DirectoryEntry( String.Concat(R ootWeb, "/", VirtualDirector y));
try
{
string name = directoryEntry. Name;
return true;
}
catch
{
bool flag = false;
return flag;
}
}

internal static void Delete(string RootWeb, string VirtualDirector y, string PhysicalDirecto ry)
{
try
{
DirectoryEntry root = new DirectoryEntry( RootWeb);
DirectoryEntry vdir = root.Children.F ind(VirtualDire ctory,
root.SchemaClas sName);
// Remove Entry from container.
string strName = vdir.Name;
root.Children.R emove(vdir);
Console.WriteLi ne(strName+ " entry is removed from container.");
root.CommitChan ges();
root.Close();
}
catch(Exception ex)
{
Console.WriteLi ne(ex.Message);
}
// delete physical dir
Directory.Delet e(PhysicalDirec tory, true);
}
}


"Jacky Luk" <no****@nospam. com> wrote in message
news:uY******** ******@TK2MSFTN GP11.phx.gbl...
Hi all,
If I need to make a C# application, do I need to set up a virtual dir such as inetroot on the Harddisks. How do I set up such thingy?
Thanks
Jack


Nov 15 '05 #3

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

Similar topics

10
3637
by: Wm. Scott Miller | last post by:
We have a intranet site that allows one of our departments to search a set of pdfs and then look at them. Only problem is that only they and us geeks should be allowed to see the pdfs. We have it locked down except for when a person directly types in the url to a pdf. Currently, the PDFs are in a virtual directory off the root of the server. Putting it under the search site also doesn't work. My understanding is that IIS looks as the...
7
2385
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)
2
2774
by: Danny Miller | last post by:
Hi there, I'm facing a problem that is driving me nuts. The scenario is as follows: 1) Create an empty directory structure e.g. C:\Dev1\TestWebApp 2) Map a virtual directory e.g. TestWebApp to this new directory 3) Under C:\Dev1 create a blank visual studio solution and add a new web project called TestWebApp (which will be created in C:\Dev1\TestWebApp and
4
2938
by: david | last post by:
I basically use the following code to display the directory and file names in the WWWROOT, but can not show the virtual directory. ---- Dim path As String = Server.MapPath(x) Dim di As DirectoryInfo = New DirectoryInfo(path) Listing.DataSource = di.GetFileSystemInfos() Listing.DataBind() ---- Anyone can help me about how to list the virtual directory.
6
5857
by: Saar Carmi | last post by:
Hi How can I get the application's virtual directory from the Application_Start method in Global.asax ? Keep in mind there is no request/response object available yet in this stage. Thanks Saar.
1
8540
by: Dave | last post by:
I am getting te following error in a ASP.Net app that is running on Win XP Pro (SP2): Server cannot access application directory 'C:\Documents and Settings\dave\My Documents\My Visual Studio ASP.NET\MyWebSite\'. The directory does not exist or is not accessible because of security settings. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information...
8
2526
by: Nate | last post by:
I am running on Window 2003. I have a website built in ASP.NET 2.0. I need to have a Virtual Directory running an application in 1.1. I have configured each in its own Application Pool. The 1.1 application picks up and parses the 2.0 web.config. It is complaining about the connectionstrings node. If I comment out that node the applications both run. I have tried running the 1.1 application under 2.0 but there are some controls used in...
2
3900
by: Rose winsle | last post by:
Hi guys ... I just wanted to create virtual directory using VB.net . i can manage that ... when i create the virtual directory how can i set anonymous access off. following is my code ============== Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/Schema/AppIsolated")
6
4335
by: ManagedCoder | last post by:
Hi, My requirement is as follows: I need to set the HttpExpires (enable content expiration - set to 7 days) on a folder within a virtual directory. I have been able to set the HttpExpires property on a virtual directory using the following code: DirectoryEntry myVdPath = new
6
3512
by: Scott M. | last post by:
I didn't get a resolution to this in my earlier post, so I'll try again: System: Windows XP Pro. (SP2) with IIS installed and running PRIOR to VS 2008 Pro. installation. VS 2008 Pro. (full installation). Installations and testing is all done via an Administrator account. If I simply create a new ASP .NET Web Application Project (WAP) on my local
0
8049
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
8469
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
8463
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
8128
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,...
1
5997
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5471
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();...
0
3953
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2461
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
1
1574
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.