Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 27th, 2005, 01:07 AM
Authorized User
 
Join Date: May 2005
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem regarding the making of virtual directory


Hi all
I am writing the code for making the virtual directory in asp.net using C#

I am having a function CreateDir() as given below and I am calling it as

string str=CreateVDir("localhost","abcd",@"d:\abc",true,t rue,true,true,true,true, 1, "localhost");

But i am getting the exception "Access is Deined " in
VDir.Properties["AccessRead"][0] = chkRead;
Please Help me

public 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;

}








Similar Threads
Thread Thread Starter Forum Replies Last Post
Virtual Directory MeenaG BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 December 2nd, 2006 01:48 PM
Problem in making database file address virtual akhilvira ASP.NET 1.0 and 1.1 Basics 0 January 4th, 2005 01:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.