-2

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?

Tomer Oszlak
  • 245
  • 1
  • 4
  • 9
  • 2
    There 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 Answers1

2

Sorry, but did you even try googling?

For checking if the file is PNG:

Community
  • 1
  • 1
Knaģis
  • 20,827
  • 7
  • 66
  • 80
  • Im trying to do it without ASP.NET Controls – Tomer Oszlak Mar 15 '13 at 20:10
  • 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