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

Help. Anyone seen or had experience with this error.

The exception is of type DirectoryNotFoundException. So check before upload if the particular directory exist.

Also are you using asp.net Upload Control or share your markup as well.
You code looks more complex than it should to do a file upload.

The exception is of type DirectoryNotFoundException. So check before upload if the particular directory exist.

Also are you using asp.net Upload Control or share your markup as well.
You code looks more complex than it should to do a file upload.

I am not using Upload Control. At least I don't think. How would I know if I am using that? Is that another file or something? That directory does exist.

ok sorry looks you are using HtmlInputFile control.
To me it looks WebFilePath.ToString is not the proper path:

To degub try this and see the path displayed is correct:

//MyPostedMember.SaveAs(WebFilePath.ToString)
Response.Write(WebFilePath.ToString)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.