Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Could not find a part of the path "\ASP.Net Practical\Website\Site1\UploadedImgs \"..

Could not find a part of the path "\ASP.Net Practical\Website\Site1\UploadedImgs \"..

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netsysadminquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Otekpo Emmanuel
    wrote on last edited by
    #1

    Good day friends! Am having problem with my asp.net project. I have two buttons on the web page. One save to “Temp Files” and the other save to “UploadedImgs”. Saving to the “Temp Files” folder do not raise any exception but saving to the “UploadedImgs” folder causes an exception which says “Could not find a part of the path 'D:\ASP.Net Practical\Website\Site1\ UploadedImgs \'.” To me, the path is 100% correct. So please, does anyone has solution to this problem? Any help will be appreciated. Below is the code am using. Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click Dim imgext As String = Path.GetExtension(FileUpload1.PostedFile.FileName) 'get image extension Dim Imgname As String = Path.GetFileName(FileUpload1.PostedFile.FileName) 'get image name Dim imgpath As String = "\ASP.Net Practical\Website\Site1\ UploadedImgs \" 'get local disk folder path FileUpload1.PostedFile.SaveAs(Server.MapPath(imgpath + Imgname + imgext)) End Sub

    J 1 Reply Last reply
    0
    • O Otekpo Emmanuel

      Good day friends! Am having problem with my asp.net project. I have two buttons on the web page. One save to “Temp Files” and the other save to “UploadedImgs”. Saving to the “Temp Files” folder do not raise any exception but saving to the “UploadedImgs” folder causes an exception which says “Could not find a part of the path 'D:\ASP.Net Practical\Website\Site1\ UploadedImgs \'.” To me, the path is 100% correct. So please, does anyone has solution to this problem? Any help will be appreciated. Below is the code am using. Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click Dim imgext As String = Path.GetExtension(FileUpload1.PostedFile.FileName) 'get image extension Dim Imgname As String = Path.GetFileName(FileUpload1.PostedFile.FileName) 'get image name Dim imgpath As String = "\ASP.Net Practical\Website\Site1\ UploadedImgs \" 'get local disk folder path FileUpload1.PostedFile.SaveAs(Server.MapPath(imgpath + Imgname + imgext)) End Sub

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #2

      Clean the save filename first, remove or strip invalid chars, then build the path based on a virtual path, not a physical path. The path will then be converted to a physical path with the Drive letter and all.

      Dim fileName as String = Clean_FileName(avatarName.ToLower() + oFileExt)
      Dim path as string = Path.Combine(Server.MapPath("~/Images/avatars/customers"), fileName)

      Public Shared Function Clean_FileName(ByVal strIn As String) As String
      ' Replace invalid characters with empty strings.
      Try
      Return Regex.Replace(strIn, "[^\w\.@-_]", "", RegexOptions.None, TimeSpan.FromSeconds(1.5))
      Catch As RegexMatchTimeoutException
      Return String.Empty
      End Try

      End Function
      
      O 1 Reply Last reply
      0
      • J jkirkerx

        Clean the save filename first, remove or strip invalid chars, then build the path based on a virtual path, not a physical path. The path will then be converted to a physical path with the Drive letter and all.

        Dim fileName as String = Clean_FileName(avatarName.ToLower() + oFileExt)
        Dim path as string = Path.Combine(Server.MapPath("~/Images/avatars/customers"), fileName)

        Public Shared Function Clean_FileName(ByVal strIn As String) As String
        ' Replace invalid characters with empty strings.
        Try
        Return Regex.Replace(strIn, "[^\w\.@-_]", "", RegexOptions.None, TimeSpan.FromSeconds(1.5))
        Catch As RegexMatchTimeoutException
        Return String.Empty
        End Try

        End Function
        
        O Offline
        O Offline
        Otekpo Emmanuel
        wrote on last edited by
        #3

        Solved: Thanks. I found the solution after so many trials. I think I should share this so that anyone with such problem could resolve it with ease. The problems was from my webpage submitting an empty filename because of the page load event. So, the solution to this problem is ensure that the uploaded filename is intact before calling the SaveAs command. Once again, thanks for your reply. Cheers!

        J 1 Reply Last reply
        0
        • O Otekpo Emmanuel

          Solved: Thanks. I found the solution after so many trials. I think I should share this so that anyone with such problem could resolve it with ease. The problems was from my webpage submitting an empty filename because of the page load event. So, the solution to this problem is ensure that the uploaded filename is intact before calling the SaveAs command. Once again, thanks for your reply. Cheers!

          J Offline
          J Offline
          jkirkerx
          wrote on last edited by
          #4

          Well yes that's a good idea. But the way your mapping out the path may backfire on you when you publish your web app for production use. Uploading files of anything requires good knowledge of how it works. There about 5 ways to do it to my knowledge. I don't use the file name of the file anymore, for now I assign my own name to the file. Later on down the road, as users keep uploading the same file with different names, you will have gigs of files sitting in the folder, and the project size will radically expand in size over the course of time. Then what? That's another topic for discussion.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups