Create directory on web site using VB.NET within asp page

Posted on 2007-10-12
Last Modified: 2013-11-26
I've been using this type of coding to create directories on desktop:

Set fs=CreateObject("Scripting.FileSystemObject")
sFolder = "C:\MyFolder"
If fs.FolderExists(sFolder) Then
Response.Write "Folder Exists"
End If

Tried using this to create sub-directory in localhost server system (sfolder="http//\localhost/MyFolder") but doesn't work.

What is the correct function and coding to use? And also for a remote website - ie if website is

how do I create, using programming in an asp page, a sub directory called images (ie

I use VB.NET rather than C#

Question by:Beish1
    LVL 14

    Expert Comment

    make sure that the web user is permitted to create folder


    Imports System.DirectoryServices

    If Not Directory.Exists("C:\MyFolder") Then
    End If
    LVL 14

    Accepted Solution

    Imports System.DirectoryServices

    Dim DirPath As String
    DirPath = Server.MapPath("/images")

    If Not Directory.Exists(DirPath) Then
    End If
    LVL 4

    Assisted Solution

    You have to use the physical path to create a directory. http//\localhost/MyFolder is not a physical directory it is virtual. But you can do:
    PhyicalPath = Server.MapPath("localhost/MyFolder")
    'Response.Write PhyicalPath
    PathArr = Split(PhyicalPath,"\")
    ThePath = PathArr(0)
    For x = 1 to UBound(PathArr)
       ThePath = ThePath & "\" & PathArr(x)
       'Response.Write ThePath
       If fs.FolderExists(ThePath) = False Then
       End If

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now