Folder creation error: "Could not find a part of the path" error

E

E. Kwong

Just a simple file upload form that allow files to be uploaded to a folder
named "media2". Code fragments are like these:

Sub btnAdd_Click(ByVal sender As Object, ByVal e As EventArgs)
If (upFile.HasFile) Then
If (CheckFileType(upFile.FileName)) Then
Dim filePath As String = "~/media2/" & upFile.FileName
upFile.SaveAs(MapPath(filePath))
lblUploadStatus.Text = upFile.FileName & " Content Type " &
upFile.PostedFile.ContentType & " Length " & upFile.PostedFile.ContentLength
& " uploaded"
Else
lblUploadStatus.Text = "File type not allowed"
End If
Else
lblUploadStatus.Text = "No file uploaded"
End If
End Sub

Sub Page_PreRender()
Dim upFolder As String = MapPath("~/media2/")
Dim dir As New DirectoryInfo(upFolder)
End Sub

..............

Found that if the folder "media2" has already been created, the program ran
fine and I'm able to upload files to that directory. However; if the
folder "media2" is non existent, the program will end with an error without
creating the new folder. In the final version of the program we
definitely need it be able to create various folders with different names.
The error message is:

Could not find a part of the path 'c:\inetpub\wwwroot\test\media2'.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.IO.DirectoryNotFoundException: Could not find a
part of the path 'c:\inetpub\wwwroot\test\media2'

Stack Trace:

[DirectoryNotFoundException: Could not find a part of the path
'c:\inetpub\wwwroot\test\media2'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
+2014368
System.IO.Directory.InternalGetFileDirectoryNames(String path, String
userPathOriginal, String searchPattern, Boolean includeFiles, Boolean
includeDirs, SearchOption searchOption) +1817
System.IO.DirectoryInfo.GetFiles(String searchPattern, SearchOption
searchOption) +57
System.IO.DirectoryInfo.GetFiles() +11
ASP.ch4_aspx.Page_PreRender() +72
System.Web.Util.CalliHelper.ArglessFunctionCaller(IntPtr fp, Object o) +5
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) +784015
System.Web.UI.Control.OnPreRender(EventArgs e) +2069340
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360


Am using XP pro and VS 2005; and everything resides in my own workstation.
I've already grant the ASPNET user Write permission to the
c:\inetpub\wwwroot\test folder. Any insight very much appreciated.
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top