views:

174

answers:

3

Hi guys

Here's my code

Dim amPhotoPath As String = "\graphics\Profiles\" & ViewState("fileName")
personalPhotoUpload.SaveAs(Server.MapPath("~") & amPhotoPath)

For some reason the image is not saving.. if I debug the code, and get the URL in Quickwatch, the folder opens, so the path is correct, but it just doesnt save! I have just set up the permissions because I thought it was because of that, but to no avail! I have no idea whats going wrong here, I am missing something?

Thanks guys

+1  A: 

Checkout the msdn example. You need to use the FileUpload controls properties to check if the FileUpload control has a file, and then use the PostedFile property to get your file name.

Mcbeev
+1 Good idea, follow a standard example first then customize if you are unsure how it works.
rick schott
A: 

Try this:

Dim amPhotoPath As String = Path.Combine(Server.MapPath("/graphics/Profiles"), ViewState("filename"))
personalPhotoUpload.SaveAs(amPhotoPath)

I'm not sure what you had in your view state, but at least this why it'll be easier to verify your path while debugging.

blesh
A: 

Did you verified that the personalPhotoUpload.ContentLength() > 0 ?

If it isn't, then that is your problem. If your filebytes is zero then there isn't an uploaded file.

Extracted from this documentation page:

The FileUpload control does not automatically read the file from the client. You must explicitly provide a control or mechanism to allow the user to submit the specified file. For example, you can provide a button that the user can click to upload the file. The code that you write to save the specified file could call the FileBytes property, which returns the contents of the file.

Before calling the FileBytes property, you should use the HasFile property to verify that the FileUpload control contains a file to upload. If the HasFile returns true, call the FileBytes property. If it returns false, display a message to the user indicating that the control does not contain a file. If you do not provide error-handling code to verify that a file exists, an attempt to save a nonexistent file throws an HttpException exception.

eKek0
The filebytes of the fileupload, is 0... what does that mean?