Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 794
  • Last Modified:

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

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"
Else
fs.CreateFolder(sFolder)
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

www.mywebsite.com 

how do I create, using programming in an asp page, a sub directory called images (ie www.mywebsite.com/images

I use VB.NET rather than C#

0
Beish1
Asked:
Beish1
  • 2
2 Solutions
 
cezarFCommented:
make sure that the web user is permitted to create folder

try...

Imports System.DirectoryServices

If Not Directory.Exists("C:\MyFolder") Then
   Directory.CreateDirectory("C:\MyFolder")
End If
0
 
cezarFCommented:
Imports System.DirectoryServices

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

If Not Directory.Exists(DirPath) Then
   Directory.CreateDirectory(DirPath)
End If
0
 
swinslowCommented:
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
      fs.CreateFolder(ThePath)
   End If
Next
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now