[英]Housekeeping on uploaded files when posting information - asp.net c# web form
I have a webform in asp.net 4.0 c# it's about posting book information to sell. 我在asp.net 4.0 c#中有一个Webform,它是关于发布要出售的图书信息的。
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?
如何管理未在.net中发布的未使用文件中的那些文件/内务处理?
Currently it's just using this aspx code: 目前,它仅使用以下aspx代码:
<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 )
{
}
}
}
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. 然后,当该网络应用启动时(计划每晚重置一次),它将删除目录中所有早于24小时的文件。
A few ideas for you: 为您提供一些建议:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.