Posts Retrieve file size from a remote URL
Post
Cancel

Retrieve file size from a remote URL

1
2
3
4
5
6
7
8
9
10
11
12
13
//http://www.kunal-chowdhury.com/2015/12/retrieve-file-size.html
private static string GetFileSize(Uri uriPath)
{
    var webRequest = HttpWebRequest.Create(uriPath);
    webRequest.Method = "HEAD";

    using (var webResponse = webRequest.GetResponse())
    {
       var fileSize = webResponse.Headers.Get("Content-Length");
       var fileSizeInMegaByte = Math.Round(Convert.ToDouble(fileSize) / 1024.0 / 1024.0, 2);
       return fileSizeInMegaByte + " MB";
    }
}

origin - http://www.pipiscrew.com/?p=2810 net-retrieve-file-size-from-a-remote-url

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags