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. File Upload error on live site.

File Upload error on live site.

Scheduled Pinned Locked Moved ASP.NET
helpasp-netvisual-studiosysadmindata-structures
14 Posts 4 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.
  • J Offline
    J Offline
    JimBob SquarePants
    wrote on last edited by
    #1

    Hi there, I'm having a pretty serious problem with file uploads not working on my live site. I was able to upload fine when I was testing in VS on my local machine. When I try to upload a file I'm getting the following error: Server Error in '/' Application. -------------------------------------------------------------------------------- Could not find a part of the path 'C:\Users\Fred\Desktop\James\Organised Files\Images\cherries.jpg'. 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:\Users\Fred\Desktop\James\Organised Files\Images\cherries.jpg'. I'm using an aspnet fileupload control and my code is as following:

    Dim photoFileUpload As FileUpload = CType(dvCrops.FindControl("photoFileUpload"), FileUpload)

        If photoFileUpload.PostedFile Is Nothing Then
    
            lblMessage.Text = "No file specified."
    
            Exit Sub
    
        Else
    
            Dim FileName As String = photoFileUpload.PostedFile.FileName
    

    All my following code requires FileName to be accurate. So i'm 100% sure my problem is on that last line. I've tried using System.IO.Path.GetFullPath but that doesn't seem to be helping. Any ideas would be really helpful. Many Thanks

    JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

    V I 2 Replies Last reply
    0
    • J JimBob SquarePants

      Hi there, I'm having a pretty serious problem with file uploads not working on my live site. I was able to upload fine when I was testing in VS on my local machine. When I try to upload a file I'm getting the following error: Server Error in '/' Application. -------------------------------------------------------------------------------- Could not find a part of the path 'C:\Users\Fred\Desktop\James\Organised Files\Images\cherries.jpg'. 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:\Users\Fred\Desktop\James\Organised Files\Images\cherries.jpg'. I'm using an aspnet fileupload control and my code is as following:

      Dim photoFileUpload As FileUpload = CType(dvCrops.FindControl("photoFileUpload"), FileUpload)

          If photoFileUpload.PostedFile Is Nothing Then
      
              lblMessage.Text = "No file specified."
      
              Exit Sub
      
          Else
      
              Dim FileName As String = photoFileUpload.PostedFile.FileName
      

      All my following code requires FileName to be accurate. So i'm 100% sure my problem is on that last line. I've tried using System.IO.Path.GetFullPath but that doesn't seem to be helping. Any ideas would be really helpful. Many Thanks

      JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

      V Offline
      V Offline
      Venkatesh Mookkan
      wrote on last edited by
      #2

      JimBob SquarePants wrote:

      Could not find a part of the path 'C:\Users\Fred\Desktop\James\Organised Files\Images\cherries.jpg'.

      The path here refer to the client machine path. It doesn't matter. Where you are trying to upload? I meant the server's location at which the uploaded files are stored.

      Castle Rider

      What if I freeze??? Don't forget to breath...

      My: Website | Yahoo Group | Blog Spot

      J 1 Reply Last reply
      0
      • V Venkatesh Mookkan

        JimBob SquarePants wrote:

        Could not find a part of the path 'C:\Users\Fred\Desktop\James\Organised Files\Images\cherries.jpg'.

        The path here refer to the client machine path. It doesn't matter. Where you are trying to upload? I meant the server's location at which the uploaded files are stored.

        Castle Rider

        What if I freeze??? Don't forget to breath...

        My: Website | Yahoo Group | Blog Spot

        J Offline
        J Offline
        JimBob SquarePants
        wrote on last edited by
        #3

        I'm actually uploading an image file directly onto a database. I can edit that database so I have appropriate access. It's just an image file from my local computer. I'm sure i've just missed out something to tell the server to look on the users computer.

        JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

        A V 2 Replies Last reply
        0
        • J JimBob SquarePants

          I'm actually uploading an image file directly onto a database. I can edit that database so I have appropriate access. It's just an image file from my local computer. I'm sure i've just missed out something to tell the server to look on the users computer.

          JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

          A Offline
          A Offline
          Anand Desai
          wrote on last edited by
          #4

          R u storing only Image full path in database or complete file?????? Because if u r storing only path, then while u retrive server reads pathe as C://.......... and tries to find that file in server's C://, and file is obviously not their. .. so its giving FileNotFound Exception I guess.... Tell me what u r doing???

          Anand Desai Developer Atharva Infotech

          1 Reply Last reply
          0
          • J JimBob SquarePants

            I'm actually uploading an image file directly onto a database. I can edit that database so I have appropriate access. It's just an image file from my local computer. I'm sure i've just missed out something to tell the server to look on the users computer.

            JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

            V Offline
            V Offline
            Venkatesh Mookkan
            wrote on last edited by
            #5

            Definitely you are missing something. Post your uploading code. Will try to find out the problem.

            Castle Rider

            What if I freeze??? Don't forget to breath...

            My: Website | Yahoo Group | Blog Spot

            J 1 Reply Last reply
            0
            • J JimBob SquarePants

              Hi there, I'm having a pretty serious problem with file uploads not working on my live site. I was able to upload fine when I was testing in VS on my local machine. When I try to upload a file I'm getting the following error: Server Error in '/' Application. -------------------------------------------------------------------------------- Could not find a part of the path 'C:\Users\Fred\Desktop\James\Organised Files\Images\cherries.jpg'. 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:\Users\Fred\Desktop\James\Organised Files\Images\cherries.jpg'. I'm using an aspnet fileupload control and my code is as following:

              Dim photoFileUpload As FileUpload = CType(dvCrops.FindControl("photoFileUpload"), FileUpload)

                  If photoFileUpload.PostedFile Is Nothing Then
              
                      lblMessage.Text = "No file specified."
              
                      Exit Sub
              
                  Else
              
                      Dim FileName As String = photoFileUpload.PostedFile.FileName
              

              All my following code requires FileName to be accurate. So i'm 100% sure my problem is on that last line. I've tried using System.IO.Path.GetFullPath but that doesn't seem to be helping. Any ideas would be really helpful. Many Thanks

              JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

              I Offline
              I Offline
              Imran Khan Pathan
              wrote on last edited by
              #6

              JimBob SquarePants wrote:

              Any ideas would be really helpful.

              When you are trying to save image on the server then this error causes. I am sure your code looks like this

              FileName.PostedFile.SaveAs(FileName.PostedFile.FileName)

              You need to Map Server path and save file there. Like this

              FileName.PostedFile.SaveAs(Server.MapPath(Path.GetFileName(FileName.PostedFile.FileName)))

              This line of code will save image on root folder

              please don't forget to vote on the post that helped you.

              A 1 Reply Last reply
              0
              • I Imran Khan Pathan

                JimBob SquarePants wrote:

                Any ideas would be really helpful.

                When you are trying to save image on the server then this error causes. I am sure your code looks like this

                FileName.PostedFile.SaveAs(FileName.PostedFile.FileName)

                You need to Map Server path and save file there. Like this

                FileName.PostedFile.SaveAs(Server.MapPath(Path.GetFileName(FileName.PostedFile.FileName)))

                This line of code will save image on root folder

                please don't forget to vote on the post that helped you.

                A Offline
                A Offline
                Anand Desai
                wrote on last edited by
                #7

                That's what I was trying to tell him 1. Create one folder (suppose: image) in your portal, 2. save that file using Server.MapPath("\\image\\" + Path.GetFileName (FileName.PostedFile.FileName)) 3. Save that path ("\image\..filename.jpeg") into database 4. Now when u want to access that file, just retrive that path from database (eg. str), and write image.URL = Server.MapPath(str). 5. That's all!!!!!!!!!! right???

                Anand Desai Developer Atharva Infotech

                1 Reply Last reply
                0
                • V Venkatesh Mookkan

                  Definitely you are missing something. Post your uploading code. Will try to find out the problem.

                  Castle Rider

                  What if I freeze??? Don't forget to breath...

                  My: Website | Yahoo Group | Blog Spot

                  J Offline
                  J Offline
                  JimBob SquarePants
                  wrote on last edited by
                  #8

                  Ok Firstly I'll give you all a quick runthrough of what I'm doing. Essentially I'm Identifing the file, loading and resizing it in memory and producing a System.Data.Linq.Binary object that is uploaded to my database. All this works when I'm running the website on my local machine. The live version can't find the file. Here Goes:

                  '----------------------------------------------------------------------------------
                  ' Name : btnAddPhoto_Click
                  ' Purpose : This event handles the Conversion of the uploaded image files to System Data Linq Binary.
                  '----------------------------------------------------------------------------------

                  Protected Sub btnAddPhoto\_Click(ByVal sender As Object, ByVal e As System.EventArgs) 'Handles btnAddPhoto.Click
                  
                      Dim photoFileUpload As FileUpload = CType(dvCrops.FindControl("photoFileUpload"), FileUpload)
                  
                  
                      If photoFileUpload.PostedFile Is Nothing Then
                  
                          lblMessage.Text = "No file specified."
                  
                          Exit Sub
                  
                      Else
                  
                          Dim FileName As String = photoFileUpload.PostedFile.FileName
                  
                  
                          Dim ext As String = FileName.Substring(FileName.LastIndexOf("."))
                  
                          ext = ext.ToLower
                  
                  
                          If ext = ".jpg" Then
                  
                          ElseIf ext = ".bmp" Then
                  
                          ElseIf ext = ".gif" Then
                  
                          ElseIf ext = "jpg" Then
                  
                          ElseIf ext = "bmp" Then
                  
                          ElseIf ext = "gif" Then
                  
                          Else
                  
                              lblMessage.Text = "Only gif, bmp, or jpg format files supported."
                  
                              Exit Sub
                  
                          End If
                  
                          ' convert the fileupload.postedfile to system.data.linq.binary
                          Dim source As FileInfo = New FileInfo(FileName)
                          Dim buffer() As Byte = New Byte(photoFileUpload.PostedFile.ContentLength - 1) {}
                          source.OpenRead.Read(buffer, 0, photoFileUpload.PostedFile.ContentLength)
                  
                  
                          buffer = ResizeImageFile(buffer, 200)
                          crpImage1 = New System.Data.Linq.Binary(buffer)
                          lblMessage.Text = "Image Successfully Uploaded."
                      End If
                  
                  End Sub
                  

                  ResizeImageFile refers to this:

                  Public Shared Function ResizeImageFile(ByVal imageFile() As Byte, ByVal targetSize As Integer) As Byte()
                  Using oldImage As System.Drawing.Image = System.Drawing.Image.FromStream(New MemoryStream(imageFile))
                  Dim newSize As Size = CalculateDimensions(oldImage.Size, targetSize)
                  Using newImage As Bitmap

                  V 1 Reply Last reply
                  0
                  • J JimBob SquarePants

                    Ok Firstly I'll give you all a quick runthrough of what I'm doing. Essentially I'm Identifing the file, loading and resizing it in memory and producing a System.Data.Linq.Binary object that is uploaded to my database. All this works when I'm running the website on my local machine. The live version can't find the file. Here Goes:

                    '----------------------------------------------------------------------------------
                    ' Name : btnAddPhoto_Click
                    ' Purpose : This event handles the Conversion of the uploaded image files to System Data Linq Binary.
                    '----------------------------------------------------------------------------------

                    Protected Sub btnAddPhoto\_Click(ByVal sender As Object, ByVal e As System.EventArgs) 'Handles btnAddPhoto.Click
                    
                        Dim photoFileUpload As FileUpload = CType(dvCrops.FindControl("photoFileUpload"), FileUpload)
                    
                    
                        If photoFileUpload.PostedFile Is Nothing Then
                    
                            lblMessage.Text = "No file specified."
                    
                            Exit Sub
                    
                        Else
                    
                            Dim FileName As String = photoFileUpload.PostedFile.FileName
                    
                    
                            Dim ext As String = FileName.Substring(FileName.LastIndexOf("."))
                    
                            ext = ext.ToLower
                    
                    
                            If ext = ".jpg" Then
                    
                            ElseIf ext = ".bmp" Then
                    
                            ElseIf ext = ".gif" Then
                    
                            ElseIf ext = "jpg" Then
                    
                            ElseIf ext = "bmp" Then
                    
                            ElseIf ext = "gif" Then
                    
                            Else
                    
                                lblMessage.Text = "Only gif, bmp, or jpg format files supported."
                    
                                Exit Sub
                    
                            End If
                    
                            ' convert the fileupload.postedfile to system.data.linq.binary
                            Dim source As FileInfo = New FileInfo(FileName)
                            Dim buffer() As Byte = New Byte(photoFileUpload.PostedFile.ContentLength - 1) {}
                            source.OpenRead.Read(buffer, 0, photoFileUpload.PostedFile.ContentLength)
                    
                    
                            buffer = ResizeImageFile(buffer, 200)
                            crpImage1 = New System.Data.Linq.Binary(buffer)
                            lblMessage.Text = "Image Successfully Uploaded."
                        End If
                    
                    End Sub
                    

                    ResizeImageFile refers to this:

                    Public Shared Function ResizeImageFile(ByVal imageFile() As Byte, ByVal targetSize As Integer) As Byte()
                    Using oldImage As System.Drawing.Image = System.Drawing.Image.FromStream(New MemoryStream(imageFile))
                    Dim newSize As Size = CalculateDimensions(oldImage.Size, targetSize)
                    Using newImage As Bitmap

                    V Offline
                    V Offline
                    Venkatesh Mookkan
                    wrote on last edited by
                    #9

                    JimBob SquarePants wrote:

                    ' convert the fileupload.postedfile to system.data.linq.binary Dim source As FileInfo = New FileInfo(FileName) Dim buffer() As Byte = New Byte(photoFileUpload.PostedFile.ContentLength - 1) {}

                    This is very wrong way of getting the bytes of uploaded file. What you are trying is, you are getting the filename and trying to get the bytes of invalid file in the server.

                    Dim FileSize As Integer = 0
                    FileSize = fileUpload.PostedFile.ContentLength
                    Dim FileData(FileSize) As Byte
                    fileUpload.PostedFile.InputStream.Read(buffer, 0, FileSize)

                    Now you will get the bytes of the selected file.

                    Castle Rider

                    What if I freeze??? Don't forget to breath...

                    My: Website | Yahoo Group | Blog Spot

                    modified on Wednesday, July 30, 2008 7:12 AM

                    J 2 Replies Last reply
                    0
                    • V Venkatesh Mookkan

                      JimBob SquarePants wrote:

                      ' convert the fileupload.postedfile to system.data.linq.binary Dim source As FileInfo = New FileInfo(FileName) Dim buffer() As Byte = New Byte(photoFileUpload.PostedFile.ContentLength - 1) {}

                      This is very wrong way of getting the bytes of uploaded file. What you are trying is, you are getting the filename and trying to get the bytes of invalid file in the server.

                      Dim FileSize As Integer = 0
                      FileSize = fileUpload.PostedFile.ContentLength
                      Dim FileData(FileSize) As Byte
                      fileUpload.PostedFile.InputStream.Read(buffer, 0, FileSize)

                      Now you will get the bytes of the selected file.

                      Castle Rider

                      What if I freeze??? Don't forget to breath...

                      My: Website | Yahoo Group | Blog Spot

                      modified on Wednesday, July 30, 2008 7:12 AM

                      J Offline
                      J Offline
                      JimBob SquarePants
                      wrote on last edited by
                      #10

                      My fingers were well and truly crossed then. Sadly no luck.

                      Dim source As FileInfo = New FileInfo(FileName

                      ) I wasn't happy with that part of the code. I'm pretty much a beginner so I'm sure there are a few more bits in there that could do with an overhaul. Could there be a problem with the way the stream is read from my computer from the server e.g should "\" be "/"?? Thanks so far!

                      JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

                      V 1 Reply Last reply
                      0
                      • J JimBob SquarePants

                        My fingers were well and truly crossed then. Sadly no luck.

                        Dim source As FileInfo = New FileInfo(FileName

                        ) I wasn't happy with that part of the code. I'm pretty much a beginner so I'm sure there are a few more bits in there that could do with an overhaul. Could there be a problem with the way the stream is read from my computer from the server e.g should "\" be "/"?? Thanks so far!

                        JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

                        V Offline
                        V Offline
                        Venkatesh Mookkan
                        wrote on last edited by
                        #11

                        As I told you before you are trying to get the bytes of a file from the user's machine in the server's location. Rather, FileUpload control automatically provides the bytes using a simple function call like fileUpload1.PostedFile.InputStream.Read(arg1, arg2, arg3) (refer my previous post for the code).

                        Castle Rider

                        What if I freeze??? Don't forget to breath...

                        My: Website | Yahoo Group | Blog Spot

                        1 Reply Last reply
                        0
                        • V Venkatesh Mookkan

                          JimBob SquarePants wrote:

                          ' convert the fileupload.postedfile to system.data.linq.binary Dim source As FileInfo = New FileInfo(FileName) Dim buffer() As Byte = New Byte(photoFileUpload.PostedFile.ContentLength - 1) {}

                          This is very wrong way of getting the bytes of uploaded file. What you are trying is, you are getting the filename and trying to get the bytes of invalid file in the server.

                          Dim FileSize As Integer = 0
                          FileSize = fileUpload.PostedFile.ContentLength
                          Dim FileData(FileSize) As Byte
                          fileUpload.PostedFile.InputStream.Read(buffer, 0, FileSize)

                          Now you will get the bytes of the selected file.

                          Castle Rider

                          What if I freeze??? Don't forget to breath...

                          My: Website | Yahoo Group | Blog Spot

                          modified on Wednesday, July 30, 2008 7:12 AM

                          J Offline
                          J Offline
                          JimBob SquarePants
                          wrote on last edited by
                          #12

                          Ok this is what I have done so far. It's still giving me the same error. Thanks for staying with me so far.

                          Dim photoFileUpload As FileUpload = CType(dvCrops.FindControl("photoFileUpload"), FileUpload)

                          Dim myfile As HttpPostedFile = photoFileUpload.PostedFile

                          Dim FileSize As Integer = 0

                          FileSize = myfile.ContentLength

                          Dim FileData(FileSize) As Byte

                          myfile.InputStream.Read(FileData, 0, FileSize)

                          FileData = ResizeImageFile(FileData, 200)

                          crpImage1 = New System.Data.Linq.Binary(FileData)

                          What am i doing wrong?

                          JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

                          V 1 Reply Last reply
                          0
                          • J JimBob SquarePants

                            Ok this is what I have done so far. It's still giving me the same error. Thanks for staying with me so far.

                            Dim photoFileUpload As FileUpload = CType(dvCrops.FindControl("photoFileUpload"), FileUpload)

                            Dim myfile As HttpPostedFile = photoFileUpload.PostedFile

                            Dim FileSize As Integer = 0

                            FileSize = myfile.ContentLength

                            Dim FileData(FileSize) As Byte

                            myfile.InputStream.Read(FileData, 0, FileSize)

                            FileData = ResizeImageFile(FileData, 200)

                            crpImage1 = New System.Data.Linq.Binary(FileData)

                            What am i doing wrong?

                            JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

                            V Offline
                            V Offline
                            Venkatesh Mookkan
                            wrote on last edited by
                            #13

                            That is it. Now it should be all set, I believe.

                            Castle Rider

                            What if I freeze??? Don't forget to breath...

                            My: Website | Yahoo Group | Blog Spot

                            J 1 Reply Last reply
                            0
                            • V Venkatesh Mookkan

                              That is it. Now it should be all set, I believe.

                              Castle Rider

                              What if I freeze??? Don't forget to breath...

                              My: Website | Yahoo Group | Blog Spot

                              J Offline
                              J Offline
                              JimBob SquarePants
                              wrote on last edited by
                              #14

                              Thanks for your help. I forgot to upload the new dll file for my site so the changes were not being implemented. Thankyou again

                              JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************

                              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