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

Discussion in 'ASP .Net Web Controls' started by E. Kwong, Nov 6, 2006.

  1. E. Kwong

    E. Kwong Guest

    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.
    E. Kwong, Nov 6, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dsh
    Replies:
    0
    Views:
    448
  2. TC
    Replies:
    3
    Views:
    26,088
    jessica
    May 19, 2004
  3. jessica
    Replies:
    0
    Views:
    1,843
    jessica
    May 20, 2004
  4. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: Error: Could not find a part of the path

    Phil Winstanley [Microsoft MVP ASP.NET], May 21, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    367
    Phil Winstanley [Microsoft MVP ASP.NET]
    May 21, 2004
  5. Gianfranco
    Replies:
    14
    Views:
    9,582
    Ollie
    Jul 28, 2005
Loading...

Share This Page