Last post Sep 10, 2006 09:39 PM by Ahmed Abdul Moniem
Sep 10, 2006 04:31 PM|Jennyf|LINK
I have created a web page to upload images to my server. Page works fine when uploading to my local server using the code
FileUpload1.SaveAs("c:\\temp\\") & FileUpload1.FileName)
when I upload the page to my server and change the following line
FileUpload1.SaveAs(Server.MapPath("~\Images\") & FileUpload1.FileName)
I get a success message from the web page but the image is not uploaded to the server.
I have set write access to the folder on the remote server. I have never used server.mappath before and think this is where the problem lies.
Can anyone advise where I'm going wrong.
Full Code Behind
Partial Class GalleryUpload
Protected Sub UploadBtn_Click(ByVal sender
ByVal e As System.EventArgs)
FileUpload1.SaveAs(Server.MapPath("~\ArdNaRiGallery\") & FileUpload1.FileName)
Label1.Text = "Received " & FileUpload1.FileName &
" Content Type " & FileUpload1.PostedFile.ContentType &
" Length " & FileUpload1.PostedFile.ContentLength
Catch ex As Exception
FileUploadReport.Text = "Failed because: <br/>" & ex.Message
FileUploadReport.Text = "File uploaded to Successfully from: <br/>" & FileUpload1.PostedFile.FileName
FileUploadReport.Text = "Please select a file before clicking " &
"the 'Upload' Button"
Sep 10, 2006 07:22 PM|Ahmed Abdul Moniem|LINK
Try to make sure of :
Server.MapPath("~\ArdNaRiGallery\") if it returns the right path or not ..
also try this:
Server.MapPath("ArdNaRiGallery") , I think you don't need the other marks ...
Sep 10, 2006 09:06 PM|Jennyf|LINK
Now working with
Sep 10, 2006 09:35 PM|mbanavige|LINK
The FileUploadReport.Text value you are setting in your catch block would be automatically overwritten with a success message once you get past :End Try
Also MapPath expects a virtual path as an argument (forward slashes)
Sep 10, 2006 09:39 PM|Ahmed Abdul Moniem|LINK
You Are Welcome :)