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