Reputation: 3
Please take some of your time and read my problem I need by using fileupload to upload just images to my web application But when I select the image and click on upload button if the program see it a jpg file it will create a directory with the name jpg an save it there That goes to gif and png Please any one if you could give the code I will be very very thankful to you Or at least link could help me
string folder = System.IO.Path.GetFileNameWithoutExtension(FileUpload1.FileName);
string path = Request.PhysicalApplicationPath + "/" + folder;
if (!System.IO.Directory.Exists(path))
System.IO.Directory.CreateDirectory(path);
string server_path = Request.PhysicalApplicationPath + "/myfiles/";
FileUpload1.SaveAs(server_path + FileUpload1.FileName);
Upvotes: 0
Views: 50
Reputation: 267
Physical path for the virtual directory using:
System.Web.Hosting.HostingEnvironment.MapPath(virtualDirectoryPath)
Upvotes: 0
Reputation: 267
You can use System.IO.Path.GetExtension(FileUpload1.FileName); to get the extension of the file.
Upvotes: 1