By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

Virtual Folder: How to create and populate?

P: n/a
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.
Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Roughly translated from
http://msdn.microsoft.com/library/de...db1142a456.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","Ser ver")))
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","V irtualDir")))
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
"žiD`" <mi****@ngi.it> wrote in message
news:43***********************@reader3.news.tin.it :
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.


Nov 23 '05 #2

P: n/a
scorpion53061 disse, il 13/11/2005 3.08:
Roughly translated from
http://msdn.microsoft.com/library/de...db1142a456.asp

(cut)

Excelly I mean a File System Virtual Directory, not an IIS one...
Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.