简体   繁体   English

获取远程文件的上次修改日期

[英]Get last modified date of a remote file

I have an app with which at startup it downloads a file from a remote location (through the net) and parses it's contents. 我有一个应用程序,通过它可以在启动时从远程位置(通过网络)下载文件并解析其内容。

I am trying to speed up the process of startup as the bigger the file gets the slower the app starts. 我试图加快启动过程,因为文件越大,应用启动速度越慢。

As a way to speed up the process I thought of getting the last modified date of the file and if it is newer from the file on the user's pc then and only then download it. 为了加快此过程,我想到了获取文件的最后修改日期,如果该文件是用户PC上的文件的较新版本,则只能下载该文件。 I have found many ways to do it online but none of them are in C# (for windows store apps). 我发现有很多在线方法,但都没有用C#(对于Windows应用商店)。 Does anybody here know of a way of doing this without the need to download the file? 这里有人知道无需下载文件的方式吗? If I am to download the file then the process is sped up at all. 如果我要下载文件,则整个过程会加快。

My C# code for downloading the file currently is this 我当前用于下载文件的C#代码是这个

const string fileLocation = "link to dropbox";
            var uri = new Uri(fileLocation);
            var downloader = new BackgroundDownloader();
            StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("feedlist.txt",CreationCollisionOption.ReplaceExisting);
            DownloadOperation download = downloader.CreateDownload(uri, file); 
            await download.StartAsync();

If it helps the file is stored in dropbox but if any of you guys have a suggestion for another free file hosting service I am open to suggestions 如果可以帮助将文件存储在保管箱中,但是如果您有其他免费文件托管服务的建议,我欢迎您提出建议

Generally, you can check the file time by sending HEAD request and parsing/looking HTTP header response for a Last-Modified filed. 通常,您可以通过发送HEAD请求并为Last-Modified字段解析/查找HTTP标头响应来检查文件时间。 The remote server should support it and DropBox does not support this feature for direct links (only via API). 远程服务器应该支持它,而DropBox不支持直接链接的此功能(仅通过API)。 But DropBox have another feature, the headers have the etag field. 但是DropBox具有另一个功能,标题具有etag字段。 You should store it and check in the next request. 您应该将其存储并签入下一个请求。 If it changed - the file has been changed too. 如果已更改-文件也已更改。 You can use this tool to check the remote file headers. 您可以使用此工具检查远程文件头。

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

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