We are excited to announce that the IIS.NET Forums are moving to the new Microsoft Q&A experience. Learn more >

Web Diecrectory (IisWebDirectory) Vs Web Virtual Directory (IisWebVirtualDir) [Answered]RSS

1 reply

Last post Sep 19, 2007 11:31 PM by steve schofield

  • Web Diecrectory (IisWebDirectory) Vs Web Virtual Directory (IisWebVirtualDir)

    Sep 17, 2007 06:06 AM|krivda|LINK

    Hi, dear experts. I am a quite novice with IIS development. And I've got a probably simple questions.

    The general task is to determine  the physical path to IIS Directories from C# code. I've found a lot of examples, suggesting to query

    Path property from IIS metabase path like  /LM/W3SVC/n/ROOT/virtual_directory_name .But that way solves only part of the problem. In My actual environment i've found that the object in this metabase path may be IisWebDirectory or IisWebVirtualDir. And if it is a IisWebDirectory it doesn't support Path property. So here are the questions:


    1. What is the difference between  IisWebDirectory and IisWebVirtualDir. (would be very greatfull for an article reference)? And what shall be used when deploying an ASP.Net Application in setup.

    2. Is isWebDirectory always hosted in this path:

    [ /LM/W3SVC/n/ROOT/].Path + "/" +"WebDirectoryName"?

    If not, how to determine its physical path. 

    3. What is the right way to query physical directory path? How to determine programmatically (preferably using DirectoryServices namespace) whether property value is inherited or not?


    Thanks alot for detailed answers. 


  • Re: Web Diecrectory (IisWebDirectory) Vs Web Virtual Directory (IisWebVirtualDir)

    Sep 19, 2007 11:31 PM|steve schofield|LINK

    Are you reading the metabase or the physical folder path?  A virtual directory is just that, 'a virtual directory'.  It is a pointer to a physical folder on disk.  Check out MSDN for more programming related documentation.



    If you are querying a physical directory path, I would use the Server.MapPath method to obtain the physical path, assuming that is what you want.  Otherwise, the System.DirectoryServices Namespace would be used to query the metabase.    Here is some code I used in IISLogsGUI that helps set properties.  It has an example of setting values in a datatable .    Hope this helps point you in the right direction.

        Private Sub SetData(ByVal SvcType As String)
                Dim EN As DirectoryEntry = New DirectoryServices.DirectoryEntry("IIS://LOCALHOST/" & SvcType)
                For Each Entry As DirectoryEntry In EN.Children
                    If IsNumeric(Entry.Name) = True Then
                        Dim DR As DataRow = CType(Me.DataGrid1.DataSource, DataTable).NewRow
                        With DR
                            .Item("Select") = 0
                            .Item("Directory") = Entry.Properties.Item("LogFileDirectory").Value
                            Select Case SvcType.Trim.ToLower
                                Case "w3svc"
                                    .Item("Type") = "WWW"
                                    .Item("Directory") &= "\w3svc" & Entry.Name
                                Case "msftpsvc"
                                    .Item("Type") = "FTP"
                                    .Item("Directory") &= "\msftpsvc" & Entry.Name
                                Case "smtpsvc"
                                    .Item("Type") = "SMTP"
                                    .Item("Directory") &= "\smtpsvc" & Entry.Name
                                Case "nntpsvc"
                                    .Item("Type") = "NNTP"
                                    .Item("Directory") &= "\nntpsvc" & Entry.Name
                            End Select
                             .Item("ID") = Entry.Name
                            .Item("Name") = Entry.Properties.Item("ServerComment").Value

                        End With
                        CType(Me.DataGrid1.DataSource, DataTable).Rows.Add(DR)
                    End If
            Catch ex As Exception
            End Try
        End Sub 


    Steve Schofield
    Windows Server MVP - IIS
    Log archival solution
    Install, Configure, Forget