Uploadingg Files w/ Hyphens in the Name

liunx

Guest
In asp.net, I'm allowing the user to upload files to their server.
Standard. However, when the file has a hyphen in the name it fails to
upload. Having hyphens in the names of the images is system critical and
there is no way we can work around it.

~~~~~~~~~~~~~~~~
sub btnUpload(Sender as Object, e as EventArgs)

Dim picPath as String = uploadThumb.PostedFile.FileName

Dim picTitle as string = System.IO.Path.GetFileName(picPath)

Try

uploadThumb.PostedFile.SaveAs("E:\web\users\jewelfire.com\images_products\thumbs\"
+ picTitle)

Span1.InnerHtml = "Upload Sucessfully.<br>File Name: " & picTitle

Span1.visible=true

catch Exp as exception

span1.InnerHtml = "An Error occured."

End Try

end sub
~~~~~~~~~~~~~~~~

Is there a trick to getting this to work with hyphens?

CaseyuploadThumb.PostedFile.SaveAs("E:\web\users\jewelfire.com\images_products\thumbs\"
+ picTitle)

Instead of a +, use the ampersand '&'.

I don't think there is a problem with hyphens. There should only be a problem with special characters such as slashs, semicolons, etc. If anything, you can also do a string.replace for all hyphens in the name i.e. replace all hyphens with an underscore.
 
Back
Top