I need to read website folders using WMI and C # in IIS 6.0. I can read virtual directories and applications using the "IISWebVirtualDirSetting" class. However, the physical folders located inside the website cannot be read using this class.
And for my case, I need to read the subfolders located on the website , and then set permission for them. For my requirement, I do not need to work with virtual directories / web services applications (which can be easily obtained using the code below ..).
I tried using the IISWebDirectory class, but it was useful.
Here is the code that reads the IIS virtual directories ...
public static ArrayList RetrieveVirtualDirList(String ServerName, String WebsiteName) { ConnectionOptions options = SetUpAuthorization(); ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISV2", ServerName), options); scope.Connect(); String SiteId = GetSiteIDFromSiteName(ServerName, WebsiteName); ObjectQuery OQuery = new ObjectQuery(@"SELECT * FROM IISWebVirtualDirSetting"); //ObjectQuery OQuery = new ObjectQuery(@"SELECT * FROM IIsSetting"); ManagementObjectSearcher WebSiteFinder = new ManagementObjectSearcher(scope, OQuery); ArrayList WebSiteListArray = new ArrayList(); ManagementObjectCollection WebSitesCollection = WebSiteFinder.Get(); String WebSiteName = String.Empty; foreach (ManagementObject WebSite in WebSitesCollection) { WebSiteName = WebSite.Properties["Name"].Value.ToString(); WebsiteName = WebSiteName.Replace("W3SVC/", ""); String extrctedSiteId = WebsiteName.Substring(0, WebsiteName.IndexOf('/')); String temp = WebsiteName.Substring(0, WebsiteName.IndexOf('/') + 1); String VirtualDirName = WebsiteName.Substring(temp.Length); WebsiteName = WebsiteName.Replace(SiteId, ""); if (extrctedSiteId.Equals(SiteId)) //if (true) { WebSiteListArray.Add(VirtualDirName ); //WebSiteListArray.Add(WebSiteName); //+ "|" + WebSite.Properties["Path"].Value.ToString() } } return WebSiteListArray; }
PS:
I need to programmatically retrieve subfolders of already deployed site (s) using WMI and C # in ASP.NET Application. I need to find subfolders of existing websites on a local or remote IIS 6.0 web server. Therefore, I require a software solution. Exactly, if I pointed to the correct class (for example, IISWebVirtualDirSetting, etc.), which I can use to get a list of physical folders on the website, then it will be very useful.
I do not work in Powershell, and I really don't need a solution that includes powershell or vbscripts.
Any alternative software way to do the same in C # / ASP.Net will also be highly appreciated.
EDIT:
GetSiteIdFromSiteName
The code might look like this:
public static int GetSiteIdFromSiteName(String ServerName, String WebsiteName) { ConnectionOptions options = SetUpAuthorization(); ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISV2", ServerName), options); scope.Connect(); ObjectQuery OQuery = new ObjectQuery(@"SELECT * FROM IIsSetting"); ManagementObjectSearcher WebSiteFinder = new ManagementObjectSearcher(scope, OQuery); ArrayList WebSiteListArray = new ArrayList(); ManagementObjectCollection WebSitesCollection = WebSiteFinder.Get(); String WebSiteName = String.Empty; foreach (ManagementObject WebSite in WebSitesCollection) { WebSiteName = WebSite.Properties["Name"].Value.ToString(); WebsiteName = WebSiteName.Replace("W3SVC/", ""); String extrctedSiteId = WebsiteName.Substring(0, WebsiteName.IndexOf('/')); break; } return extrctedSiteId; }
and
SetupAuthorization ()
Here is the SetupAuthorization function.
public ConnectionOptions SetUpAuthorization() { ConnectionOptions options = new ConnectionOptions();
Hi