csharphelp

csharphelp

  • NA
  • 28
  • 0

Problem regarding the making of virtual directory

Oct 27 2005 2:05 AM
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,true,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;

}