C# .NET - Making a folder virtual folder on button click in
Asked By csharp help
26-Oct-05 06:59 AM
Hi All Please tell me is there any way from which i can make a folder a virtual folder by clicking a button in asp.net using C#
See article here--
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=621
se this
http://www.c-sharpcorner.com/Code/2002/July/CreateVirtualDirs.asp
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,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;
}

is inherited, using System.DirectoryServices? IIS I have some C# code that looks like this: DirectoryEntry poolDirEntry = new DirectoryEntry(); bool found = false; try { poolDirEntry = new DirectoryEntry("IIS: / / foo / W3SVC / AppPools / AnApplicationPool"); / / properties[foo].Count will always return > 0 if there is true; } if (found = = true) { poolDirEntry.CommitChanges(); / / log a change was made } else { / / do nothing } } catch exception foo. . The problem is that Properties["WAMUserName"].Count is always greater than 0, because it false if the property is not defined at all, or is inherited.< / returns> private static bool PropertyDefinedExplicitly(DirectoryEntry iisNode, String propertyName) { / / check 1. this node has a valid key-type, and 2. it is, inherited, , using, , , , System.DirectoryServices? description: I have some C# code that looks like this: DirectoryEntry poolDirEntry = new DirectoryEntry(); bool found = false; try
an application? string ServerPath = String.Format("IIS: / / {0} / W3SVC / {1} / Root", ModelBase.ServerName, ModelBase.SiteIISId); DirectoryEntry site = new DirectoryEntry(ServerPath); string className = site.SchemaClassName.ToString(); if ((!className.EndsWith("Server")) && (!className.EndsWith("VirtualDir"))) throw new Exception("The provided Metabase path is invalid."); bool WebSiteExists = DirectoryEntry.Exists(ServerPath + " / " + ModelBase.Abbreviation); if (!WebSiteExists) { CreateDirectory(new DirectoryInfo(ModelBase.TemplateDirectoryPath), new DirectoryInfo(ModelBase.SiteDirectoryPath if (path = = null) throw new ArgumentNullExpcetion("path"); if (name = = null) throw new ArgumentNullException("name"); using (DirectoryEntry entry = new DirectoryEntry(path)) { entry.Invoke("AppCreate2", new object[1] { (int)flag }); entry.Properties["AppFriendlyName"].Value = name; if public class MkVdir { public MkVdir() { } public static string CreateVDir(string WebSite, string VDirName, string Path, bool RootDir, bool chkRead, bool chkWrite, bool chkExecute, bool chkScript, bool chkAuth, int webSiteNum, string serverName
System.Runtime.InteropServices.COMException Hi All, Im getting follwing Exception. . . . System.Runtime.InteropServices.COMException was unhandled by user code Message = "Unspecified error \ r \ n" Source = "System.DirectoryServices" ErrorCode = -2147467259 StackTrace: at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) at System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_AdsObject() at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne) at System.DirectoryServices.DirectorySearcher.FindAll() at Login System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) This is my code. . . . public static bool UserExists( string UserName, string Password) { / / create an instance of the DirectoryEntry DirectoryEntry de = GetDirectoryObject(UserName, Password); / / create instance fo the direcory searcher DirectorySearcher deSearch = new DirectorySearcher (); / / set and password do match, then this implies a valid login / / if so then return the DirectoryEntry object if (results.Count = = 0) { return false ; } else { return true ; } } private static DirectoryEntry GetDirectoryObject( string
which authenticates users against ActiveDirectory. I am using the following code for changing the password. DirectoryEntry uEntry = new DirectoryEntry ( "LDAP: / / xtramile.com" , user, pwd, AuthenticationTypes .Secure); object [] objnewpwd = new object [] { newpwd }; object [] objrenewpwd = new Properties[ "LockOutTime" ].Value = 0; / / unlock account uEntry.Close(); I am getting the error 'Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))'. Can any one explain what is the cause for this? Appreciate Net Use this code to changed the password protected void SubmitNewPasswordToAD(string username, string password) { DirectoryEntry DE; string ADPath = " LDAP: / / edited "; DE = new DirectoryEntry(ADPath, username, password, AuthenticationTypes.Secure); try { string NewPassword = GenerateRandomPassword(); DE.Invoke("ChangePassword", new object[] { password NewPassword }); DE.CommitChanges(); Message.Text + = " " + NewPassword; } catch (Exception excep) { Message.Text + = ("Error changing password. Reason: " + excep.Message); } } In your code you did not correct, and if so, change the password in Active Directory. First, you will get the DirectoryEntry object and then invoke the ChangePassword function. / / Connect to Active Directory and get the DirectoryEntry object. / / Note, ADPath is an Active Directory path pointing to a user. You would have