Reputation: 1
I have a webform in asp.net 4.0 c# it's about posting book information to sell.
Currently if user upload the book image and not click the "submit" button, the file will still be in my local drive. How do I manage those file/housekeeping on unused file that was not any part of post in .net?
Currently it's just using this aspx code:
<asp:FileUpload ID="flupload1" runat="server" />
<asp:RegularExpressionValidator ID="revImage" runat="server" ControlToValidate="flupload1"
ValidationGroup="sell" Display="Dynamic" ForeColor="Red" Text=" Invalid image type"
ValidationExpression="^.*\.((j|J)(p|P)(e|E)?(g|G)|(g|G)(i|I)(f|F)|(p|P)(n|N)(g|G))$" />
for code behind:
protected void uploadBtn1_Click(object sender, EventArgs e)
{
if (flupload1.HasFile)
{
flupload1.SaveAs(Server.MapPath("productImages") + "//" + flupload1.FileName);
try
{
img1.ImageUrl = "ProductImages//" + flupload1.FileName;
}
catch (Exception )
{
}
}
}
Upvotes: 0
Views: 395
Reputation: 18654
A few ideas for you:
Upvotes: 0
Reputation: 44931
The way that we handle similar issues is to have all of the temporary files (uploads, files requested for download) stored in a temporary, well-known directory in the web site.
Then, when the web app starts (it is scheduled to reset nightly), it removes all files in the directory that are older than 24 hours.
Upvotes: 1