简体   繁体   English

从inputstream获取文件路径?

[英]Get file path from inputstream?

I am trying to get the last modified date from a file, but need its path? 我正在尝试从文件中获取最后修改日期,但是需要它的路径吗? Could someone please show me how i can get the file path? 有人可以告诉我如何获取文件路径吗?

[HttpGet]
public string uploadfile(string token, string filenameP, DateTime modDate, HttpPostedFileBase file)
{
    MemoryStream target = new MemoryStream();   
    file.InputStream.CopyTo(target);    
    byte[] data = target.ToArray();

    //ModDate = File.GetLastWriteTimeUtc("Path");
}

You are creating a new file on the server when you upload. 上传时,您正在服务器上创建一个新文件。 The last modified date will be "now" (the time the file is created). 上次修改的日期为“现在”(创建文件的时间)。 There is no way to snoop the user's machine to get this information (which is not part of the file itself). 无法窥探用户的计算机以获取此信息(这不是文件本身的一部分)。 Can't be done with an HTTP form upload. 无法完成HTTP表单上传。

Now, some file types may contain metadata in the file which may have pertinent information. 现在,某些文件类型可能在文件中包含可能具有相关信息的元数据。 If you know the file type and it does contain such metadata then you can open the file and have a look. 如果您知道文件类型并且它确实包含此类元数据,则可以打开文件并进行查看。

You just don't. 你只是没有。 Most (if not all) browsers do not provide this information for security reasons in internet sceanrios. 出于安全原因,大多数(如果不是全部)浏览器在Internet sceanrios中都不提供此信息。

You can read date by javascript (HTML5) and send it as hidden input field of form. 您可以通过javascript(HTML5)阅读日期,并将其作为表单的隐藏输入字段发送。 Something like 就像是

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // files is a FileList of File objects. List some properties.
    var output = [];
    for (var i = 0, f; f = files[i]; i++) {
      output.push(f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() );
    }
    document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
  }
  document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>

http://www.html5rocks.com/en/tutorials/file/dndfiles/ http://www.html5rocks.com/en/tutorials/file/dndfiles/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM