Reputation: 833
My project has a feature for uploading files. The uploaded files are saved in a folder named "My Files". I have some web control that I can use to remove or add the files. I can remove files with the control but not those that have been uploaded to "My Files" folder. how can I do it?
Here is my code for adding file to "My Files" folder:
for (int i = 0; i < MyArray.Length; i++){
fileName = Request.QueryString["ID"] + "_" + valesArray[i];
Request.Files["ctrl-" + i ].SaveAs(Server.MapPath("") + "\\MyFiles\\" + fileName);
MyCommand.Parameters.AddWithValue("@Upld_" + i, "MyFiles/" + fileName);
}
Upvotes: 1
Views: 1832
Reputation: 2014
assuming that remove means delete, try this:
using System.IO;
File.Delete ( string.Format ( @"{0}\{1}", Server.MapPath ( "MyFiles" ), fileName ) );
Upvotes: 1