Home All Groups Group Topic Archive Search About

Create a Virtual Directory with System.DirectoryServices

Author
3 Feb 2006 11:19 AM
gralet
Hi everyone

I need to create a Virtual Directory for IIS 5.1 from .NET, I found (thanks
to Dmytro Lapshyn [MVP]) in MSDN a page that shows an ""example"" of how to
do it, but in fact the example is no there, maybe de docs are in beta
versions or something like that, can anyone help me???

This is the link of the ""example"": http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/425ff52d-9998-44a9-95dd-b46b2e390db8.asp
--
__________________
Luis Graillet Ramos

Author
3 Feb 2006 11:30 AM
gralet
Sorry, that wasnt the link, this is te correct one: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/4d4dc778-7c31-48d0-a758-37db1142a456.asp
--
__________________
Luis Graillet Ramos


Show quote
"gralet" wrote:

> Hi everyone
>
> I need to create a Virtual Directory for IIS 5.1 from .NET, I found (thanks
> to Dmytro Lapshyn [MVP]) in MSDN a page that shows an ""example"" of how to
> do it, but in fact the example is no there, maybe de docs are in beta
> versions or something like that, can anyone help me???
>
> This is the link of the ""example"":
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/425ff52d-9998-44a9-95dd-b46b2e390db8.asp
> --
> __________________
> Luis Graillet Ramos
Author
3 Feb 2006 3:59 PM
gralet
I found a code example in a vb forum to Create a Virtual Directory with
System.DirectoryServices, if anyone need it:

Module Module1

    Sub Main()
        Module1.CreateVirtualDir("localhost", "NewVDir",
"C:\Projects\NewContent")
        Console.ReadLine()
    End Sub

    Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As
String, ByVal Path As String)

        Dim IISSchema As New
System.DirectoryServices.DirectoryEntry("IIS://" & WebSite &
"/Schema/AppIsolated")
        Dim CanCreate As Boolean = Not
IISSchema.Properties("Syntax").Value.ToString.ToUpper() = "BOOLEAN"
        IISSchema.Dispose()

        If CanCreate Then
            Dim PathCreated As Boolean

            Try
                Dim IISAdmin As New
System.DirectoryServices.DirectoryEntry("IIS://" & WebSite & "/W3SVC/1/Root")

                'make sure folder exists
                If Not System.IO.Directory.Exists(Path) Then
                    System.IO.Directory.CreateDirectory(Path)
                    PathCreated = True
                End If

                'If the virtual directory already exists then delete it
                For Each VD As System.DirectoryServices.DirectoryEntry In
IISAdmin.Children
                    If VD.Name = AppName Then
                        IISAdmin.Invoke("Delete", New String()
{VD.SchemaClassName, AppName})
                        IISAdmin.CommitChanges()
                        Exit For
                    End If
                Next VD

                'Create and setup new virtual directory
                Dim VDir As System.DirectoryServices.DirectoryEntry =
IISAdmin.Children.Add(AppName, "IIsWebVirtualDir")
                VDir.Properties("Path").Item(0) = Path
                VDir.Properties("AppFriendlyName").Item(0) = AppName
                VDir.Properties("EnableDirBrowsing").Item(0) = False
                VDir.Properties("AccessRead").Item(0) = True
                VDir.Properties("AccessExecute").Item(0) = True
                VDir.Properties("AccessWrite").Item(0) = False
                VDir.Properties("AccessScript").Item(0) = True
                VDir.Properties("AuthNTLM").Item(0) = True
                VDir.Properties("EnableDefaultDoc").Item(0) = True
                VDir.Properties("DefaultDoc").Item(0) =
"default.htm,default.aspx,default.asp"
                VDir.Properties("AspEnableParentPaths").Item(0) = True
                VDir.CommitChanges()

                'the following are acceptable params
                'INPROC = 0
                'OUTPROC = 1
                'POOLED = 2
                VDir.Invoke("AppCreate", 1)

            Catch Ex As Exception
                If PathCreated Then
                    System.IO.Directory.Delete(Path)
                End If
                Throw Ex
            End Try
        End If
    End Sub

End Module



__________________
Luis Graillet Ramos


Show quote
"gralet" wrote:

> Sorry, that wasnt the link, this is te correct one:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/4d4dc778-7c31-48d0-a758-37db1142a456.asp
> --
> __________________
> Luis Graillet Ramos
>
>
> "gralet" wrote:
>
> > Hi everyone
> >
> > I need to create a Virtual Directory for IIS 5.1 from .NET, I found (thanks
> > to Dmytro Lapshyn [MVP]) in MSDN a page that shows an ""example"" of how to
> > do it, but in fact the example is no there, maybe de docs are in beta
> > versions or something like that, can anyone help me???
> >
> > This is the link of the ""example"":
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/html/425ff52d-9998-44a9-95dd-b46b2e390db8.asp
> > --
> > __________________
> > Luis Graillet Ramos

AddThis Social Bookmark Button