[英]Get meta data of a file using c#
我需要使用c#查找文件的元数据。我使用的文件保存在第三方站点中。 我可以从该服务器下载文件,但无法获取我下载的文件的原始元数据。 如何使用c#来实现这一点。下面是我的代码。
string FilePath = AppDomain.CurrentDomain.BaseDirectory + @"Downloads\";
string Url = txtUrl.Text.Trim();
Uri _Url = new Uri(Url);
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(_Url);
request.Timeout = Timeout.Infinite;
System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
response.Close();
if (response.ContentType != "text/html; charset=UTF-8")
{
string FileSize = response.Headers.Get("Content-Length");
int lastindex = Url.LastIndexOf("/");
string TempUrlName = Url.Substring(lastindex + 1, Url.Length - (lastindex + 1));
WebClient oWebClient = new WebClient();
oWebClient.DownloadFile(txtUrl.Text.Trim(), FilePath + @"\" + TempUrlName);
if (File.Exists(FilePath + @"\" + TempUrlName))
{
FileInfo oInfo = new FileInfo(FilePath + @"\" + TempUrlName);
DateTime time = oInfo.CreationTime;
time = oInfo.LastAccessTime;
time = oInfo.LastWriteTime;
}
}
只有将文件保存在本地后,我才能获取文件大小,创建时间,上次访问时间和上次写入时间。 但是当文件使用c#位于服务器中时,我需要文件元数据信息。
谢谢
由于这些属性存储在文件系统中,并且一旦在本地保存后就更改了,因此您将无法通过HTTP访问这些属性。
您对第三方有影响吗? 也许他们会在标头中发送这些属性?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.