如何检索“上次修改日期"?ASP.Net中上传的文件数 [英] How to retrieve "Last Modified Date" of uploaded file in ASP.Net

查看:49
本文介绍了如何检索“上次修改日期"?ASP.Net中上传的文件数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个网站,客户端在其中上传一些文档文件,例如doc,docx,htm,html,txt,pdf等.我想检索上载文件的上次修改日期.我创建了一个处理程序(.ashx),用于保存文件.

I am developing a website, in which client uploads some document files like doc, docx, htm, html, txt, pdf etc. I want to retrieve last modified date of an uploaded file. I have created one handler(.ashx) which does the job of saving the files.

Following is the code:
HttpPostedFile file = context.Request.Files[i];                                 
string fileName = file.FileName;                               
file.SaveAs(Path.Combine(uploadPath, filename));

如您所见,使用file.SaveAs()方法保存文件非常简单.但是,这个HttpPostedFile类没有公开任何属性来检索文件的最后修改日期.

As you can see, its very simple to save the file using file.SaveAs() method. But this HttpPostedFile class is not exposing any property to retrieve last modified date of file.

那么谁能告诉我在保存文件到硬盘之前如何检索文件的最后修改日期?

推荐答案

今天,您可以使用HTML5 API从客户端访问此信息

Today you can access to this information from client side using HTML5 api

//fileInput is a HTMLInputElement: <input type="file" multiple id="myfileinput"> 
var fileInput = document.getElementById("myfileinput");
// files is a FileList object (simliar to NodeList) 
var files = fileInput.files;
for (var i = 0; i < files.length; i++) {
    alert(files[i].name + " has a last modified date of " + files[i].lastModifiedDate);
}

来源和更多信息

这篇关于如何检索“上次修改日期"?ASP.Net中上传的文件数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆