1

I have to resize the image before saving

for that i have file uploader and a resizer function

in function i required to pass the full path of uploaded image

System.Drawing.Image oImg = System.Drawing.Image.FromFile(_uploadImageFile.PostedFile.FileName.ToString());

i tried FileUpload1.PostedFile.FileName

but in any case it returns me only file name , not the full path

i also gone through stack overflow some questions, but all of them are returning only file name, i want to have full path

Get full path of a file with FileUpload Control

how to get the full path of file upload control in asp.net?

Community
  • 1
  • 1
Your father
  • 97
  • 1
  • 11
  • Even `Server.MapPath(FileUpload1.FileName);`in the link you provide, give you only the file name? – provençal le breton Jul 15 '13 at 09:57
  • Why dont you use the FromStream method instead to get the image? – Patrick Jul 15 '13 at 09:57
  • 2
    Assuming a webpage, why would you want the full filename? You cannot read it from the client anyway, it is posted to the server. The contents of the uploaded file is in the PostedFile object. – Maarten Jul 15 '13 at 09:58
  • I have to re size the image before saving to server, one alternate i have to first save original file , then access it and resize, and after re sizing delete the original file , but i dont this method is accurate – Your father Jul 15 '13 at 09:59

1 Answers1

1

The method System.Drawing.Image.FromFile expect the file to be presented on the server, but when you use _uploadImageFile.PostedFile.FileName this is the file which was picked up on the client.
So obviously System.Drawing.Image.FromFile(); will not find it because you pass it a client path.

I would recomment you to use other methods like Image.FromStream(Stream);, you can pass input file stream and you can get the image.

jAC
  • 5,195
  • 6
  • 40
  • 55
Alexandr Mihalciuc
  • 2,537
  • 15
  • 12