CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Posts
    13

    Error uploading file - Could not find a part of the path

    I am having trouble uploading any file to the path in the error message below. Does anyone have any idea what the problem is. I did some research on this and most sites say that the permissions need Read/Write access for the asp.net user. I tried this and I still receiver the error. Here is the error:

    For example Error saving file education_calendar.pdf System.IO.DirectoryNotFoundException: Could not find a part of the path "d:\inetpub\aopha\Uploads\". at System.IO.__Error.

    Here is my code for the click event. I am not sure what is happening here:

    Private Sub cmdUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpload.Click
    If IsPostBack Then
    Dim MyFileColl As HttpFileCollection = Request.Files
    Dim MyPostedMember As HttpPostedFile = MyFileColl.Get("File1")
    Dim MyFileName As String = MyPostedMember.FileName

    If Not MyPostedMember Is Nothing Then
    Try
    Dim intFileNameLength As Integer = InStr(1, StrReverse(MyFileName), "\")
    Dim strFileNameOnly As String = Mid(MyFileName, (Len(MyFileName) - intFileNameLength) + 2)
    Dim RootPath As String = Server.MapPath("/")

    'APPEND THE APPROPRIATE FOLDER
    Dim tmpFolder As String = FileLoc.SelectedValue 'HttpContext.Current.Request.Form("FileLoc")
    Dim WebFilePath As String = Server.MapPath(tmpFolder & strFileNameOnly) 'HttpContext.Current.Request.MapPath(tmpFolder & strFileNameOnly)

    MyPostedMember.SaveAs(WebFilePath.ToString)

    Dim LinkPath As String = WebFilePath.Replace(RootPath, "")
    LinkPath = "/" & LinkPath.Replace("\", "/")

    lblMessage.Text = "Successfully saved file: <a href=""" & LinkPath & """ target=""_blank"">" _
    & tmpFolder & strFileNameOnly & "</a>"

    'return the file to the opening window.

    Dim strScript As String = "<script>window.opener.document.forms(0)." + control.Value + ".value = '"

    If Request.QueryString("retPath") = "link" Then
    strScript += LinkPath
    Else
    strScript += strFileNameOnly
    End If

    strScript += "';self.close()"
    strScript += "</" + "script>"
    RegisterClientScriptBlock("anything", strScript)
    Catch exc As Exception
    lblMessage.Text = "Error saving file <b>" _
    & File1.Value & "</b><br>" & exc.ToString()
    End Try
    End If
    End If
    End Sub

  2. #2
    Join Date
    Oct 2009
    Posts
    13

    Re: Error uploading file - Could not find a part of the path

    ANyone have any ideas on this please?

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Error uploading file - Could not find a part of the path

    IIS doesn't know about inetpub. Use RELATIVE addressing. .\images
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Oct 2009
    Posts
    13

    Re: Error uploading file - Could not find a part of the path

    I looked at my web.config which is what is setting the path and the inetpub folder is used in the web.config but not where it is calling to upload the paths. This is the configuration for UploadPaths in web.config:


    <PCMS>
    <UploadPaths>
    <add key="General Uploads" value="/Uploads/"/>
    <add key="Upload Images" value="/Uploads/images/"/>
    <add key="Public Documents" value="/Uploads/PublicDocuments/"/>
    <add key="PDF Files" value="/pdf_files/"/>
    <add key="Sustaining Firm Images" value="/member_photos/"/>
    </UploadPaths>
    </PCMS>

    I still receive the error. What am I doing wrong here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured