Create a virtual Directory ASP.NET

I am using the following code in order to create a Virtual Directory in ASP.NET:


<%@ Import Namespace="System" %>
<%@ Import Namespace="System.EventArgs" %>
<%@ Import Namespace="System.DirectoryServices" %>
<%@ Page Language="VB" Debug="true" %>

<script language="VB" runat="server">
 Private Sub CreateVirtualDir(ByVal WebSite As String, ByVal AppName As String, ByVal Path As String)

                  path = "D:\Software"
                  
                  AppName = "TestDir"
                  
                  
                  Dim IISSchema As New System.DirectoryServices.DirectoryEntry("IIS://" & "localhost" & "/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 DirectoryEntry("IIS://LM/W3SVC/1529167522/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

</script>

The problem is that I get the following error:

"BC30002: Type 'DirectoryEntry' is not defined."

This is the error line:                       Line 14:                   Dim IISSchema As New DirectoryEntry("IIS://" & "localhost" & "/Schema/AppIsolated")

Can you help me to figure out what is not working ?
performadsignAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

appariCommented:
did you add reference System.DirectoryServices to your project or not?
if not Add reference to System.DirectoryServices( Select project right cilck add reference, in the add reference dialog select System.DirectoryServices  and click add)
0
cnagaraj25Commented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SystemExpertCommented:
yes you can Create FTP and Web IIS Virtual Directory using C#

see the following Link

http://www.c-sharpcorner.com/Code/2002/July/CreateVirtualDirs.asp

Thanks
0
performadsignAuthor Commented:
Ok I did what "cnagaraj25"  suggested and it worked. I do not get any errors anymore. When I go to IIS Manager I cannot see my created virtual folder under the "Default Web Site". Also i changed the virtual directory entry to ("IIS://W3SVC/localhost/1/Root")

Is there any way for me to check or make sure it was created? and would it be seen in the IIS manager
 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Storage Software

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.