Virtual Folder: How to create and populate?

  • Thread starter =?ISO-8859-1?Q?=A7iD=60?=
  • Start date
?

=?ISO-8859-1?Q?=A7iD=60?=

Hi!

I would like to create a virtual folder (which I want to mount) and
populate managing his content by a DLL or something like that in VB.NET
(2.0).

How can I acomplish this?


Thanks to all!
sid.
 
S

scorpion53061

Roughly translated from
http://msdn.microsoft.com/library/d...html/4d4dc778-7c31-48d0-a758-37db1142a456.asp

Imports System
Imports System.IO
Imports System.DirectoryServices
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Collections

Namespace System_DirectoryServices_DirectoryEnTry_ConfigIIS
Class Program
Shared Sub Main(ByVal args() As String)

...
CreateSite("IIS://Localhost/W3SVC", "555", "MySite",
"D:\\Inetpub\\Wwwroot")

...
SetSingleProperty("IIS://Localhost/W3SVC/555",
"ServerBindings", ":8080:")

...
CreateVDir("IIS://Localhost/W3SVC/1/Root", "MyVDir",
"D:\\Inetpub\\Wwwroot")

...
End Sub

...
Shared Sub CreateSite(ByVal metabasePath As String, ByVal siteID
As String, ByVal siteName As String, ByVal physicalPath As String)
' metabasePath is of the form "IIS://<servername>/<service>"
' for example "IIS://localhost/W3SVC"
' siteID is of the form "<number>", for example "555"
' siteName is of the form "<name>", for example, "My New Site"
' physicalPath is of the form "<drive>:\<path>", for example,
"C:\Inetpub\Wwwroot"
Console.WriteLine("\nCreating site {0}/{1}, mapping the Root
application to {2}:",
metabasePath, siteID, physicalPath)

Try
Dim service As DirectoryEnTry = New
DirectoryEnTry(metabasePath)
Dim className As String = service.SchemaClassName.ToString()
If className.EndsWith("Service") Then
Dim sites As DirectoryEntries = service.Children
Dim NewSite As DirectoryEnTry =
sites.Add(siteID,(className.Replace("Service","Server")))
NewSite.Properties("ServerComment")(0) = siteName
NewSite.CommitChanges()

Dim NewRoot As DirectoryEnTry
NewRoot = NewSite.Children.Add("Root", "IIsWebVirtualDir")
NewRoot.Properties("Path")(0) = physicalPath
NewRoot.Properties("AccessScript")(0) = True
NewRoot.CommitChanges()

Console.WriteLine(" Done. Your site will not start until you
set the ServerBindings or SecureBindings property.")
Else
Console.WriteLine(" Failed. A site can only be created in a
service node.")
End If
Catch ex As Exception
Console.WriteLine("Failed in CreateSite with the following
exception: \n{0}", ex.Message)
End Try
End Sub

...
Shared Sub SetSingleProperty(ByVal metabasePath As String, ByVal
propertyName As String, ByVal NewValue As Object)
' metabasePath is of the form "IIS://<servername>/<path>"
' for example "IIS://localhost/W3SVC/1"
' propertyName is of the form "<propertyName>", for example
"ServerBindings"
' value is of the form "<intStringOrBool>", for example, ":80:"
Console.WriteLine("\nSetting single property at {0}/{1} to {2}
({3}):",
metabasePath, propertyName, NewValue,
NewValue.GetType().ToString())

Try
Dim path As DirectoryEnTry = New DirectoryEnTry(metabasePath)
Dim propValues As PropertyValueCollection =
path.Properties(propertyName)
Dim oldType As String = propValues.Value.GetType().ToString()
Dim NewType As String = NewValue.GetType().ToString()
Console.WriteLine(" Old value of {0} is {1} ({2})",
propertyName, propValues.Value, oldType)
If NewType = oldType Then
path.Properties(propertyName)(0) = NewValue
path.CommitChanges()
Console.WriteLine("Done")
Else
Console.WriteLine(" Failed in SetSingleProperty; type of
new value does not match property")
End If
Catch ex As Exception
If "HRESULT 0x80005006" = ex.Message Then
Console.WriteLine(" Property {0} does not exist at {1}",
propertyName, metabasePath)
Else
Console.WriteLine("Failed in SetSingleProperty with the
following exception: \n{0}", ex.Message)
End If
End Try
End Sub

...
Shared Sub CreateVDir(ByVal metabasePath As String, ByVal vDirName
As String, ByVal physicalPath As String)
' metabasePath is of the form
"IIS://<servername>/<service>/<siteID>/Root[/<vdir>]"
' for example "IIS://localhost/W3SVC/1/Root"
' vDirName is of the form "<name>", for example, "MyNewVDir"
' physicalPath is of the form "<drive>:\<path>", for example,
"C:\Inetpub\Wwwroot"
Console.WriteLine("\nCreating virtual directory {0}/{1}, mapping
the Root application to {2}:",
metabasePath, vDirName, physicalPath)

Try
Dim site As DirectoryEnTry = New DirectoryEnTry(metabasePath)
Dim className As String = site.SchemaClassName.ToString()
If (className.EndsWith("Server"))
||(className.EndsWith("VirtualDir")) Then
Dim vdirs As DirectoryEntries = site.Children
Dim NewVDir As DirectoryEnTry =
vdirs.Add(vDirName,(className.Replace("Service","VirtualDir")))
NewVDir.Properties("Path")(0) = physicalPath
NewVDir.Properties("AccessScript")(0) = True
' These properties are necessary for an application to be
created.
NewVDir.Properties("AppFriendlyName")(0) = vDirName
NewVDir.Properties("AppIsolated")(0) = "1"
NewVDir.Properties("AppRoot")(0) = "/LM" +
metabasePath.Substring(metabasePath.IndexOf("/", ("IIS://".Length)))

NewVDir.CommitChanges()

Console.WriteLine(" Done.")
Else
Console.WriteLine(" Failed. A virtual directory can only be
created in a site or virtual directory node.")
End If
Catch ex As Exception
Console.WriteLine("Failed in CreateVDir with the following
exception: \n{0}", ex.Message)
End Try
End Sub

...
End Class
End Namespace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top