How to get LastModidifiedDate or ContentLength of any remote file on the
internet?
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
DateTime date= res.LastModified;
This snippet of code can get the last modidifcation date of a remote file
without downloading it also can get content length.
But this code work on desktop mode only. The alternative for this on
Widows Phone 8 is something like this.
private void Get(string uri) { Uri targetUri = new Uri(uri,
UriKind.Absolute);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri);
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback),
request);
}
private void ReadWebRequestCallback(IAsyncResult callbackResult) {
HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
HttpWebResponse myResponse =
(HttpWebResponse)myRequest.EndGetResponse(callbackResult);
}
But the problem is that the file must be downloaded first. What should I
do to get rid of that?
No comments:
Post a Comment