Im using ASP.NET web forms and C#. I want to upload images to a specific folder and to rename the file to some name and not to upload the file if its not a PNG. I dont have a clue how to do it, some help please?
Asked
Active
Viewed 9,944 times
-2
-
2There are multiple resources on the web for doing this... Check this (http://stackoverflow.com/questions/3167240/asp-net-file-upload) and this (http://asp.net-tutorials.com/controls/file-upload-control/) – Agustin Meriles Mar 14 '13 at 20:35
-
This is a big vague. What have you tried? There are plenty of tutorials online on how to upload things. And checking the file extension of the uploaded file is really simple. I think this question is too vague to get a real answer, short of someone simply writing a solution for you. – Eli Gassert Mar 14 '13 at 20:36
-
Try google: https://www.google.com/search?q=upload+file+in+asp.net+C%23+web+form+%2B+stackoverflow+site:stackoverflow.com&biw=1366&bih=621&sa=X&ved=2ahUKEwizqPm5q67yAhUPgP0HHVNKCfwQrQIoBHoECAUQBQ – Aug 13 '21 at 15:44
1 Answers
2
Sorry, but did you even try googling?
- http://www.codeproject.com/Articles/1757/File-Upload-with-ASP-NET
- http://msdn.microsoft.com/en-us/library/aa479405.aspx
- http://asp.net-tutorials.com/controls/file-upload-control/
For checking if the file is PNG:
-
-
I tried this code if (Request.Form.Count > 0) { HttpPostedFile file = Request.Files["file"]; //check file was submitted if (file != null && file.ContentLength > 0) { string fname = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath(Path.Combine("../images/airports", fname))); } } and its not working, i dont get any error but the file is not uploaded – Tomer Oszlak Mar 15 '13 at 20:29