Retrieve File Size From Remote URL using C#

The system API class System.Net.HttpWebRequest allows you to retrieve the file information programmatically. The size of each file/page generally available in the header section of web response, which you can query to get it.
Header contains Content-Length property value which gives you the size of the file in bytes. This you can later calculate to convert in MB or GB.

Here’s the source code that can be used:

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";

Get Root Domain and Favicon from URL in C#

In this quick tip I will show you a simple way to retrieve Root Domain and favicon icon from URL using C#. Its quite useful if you are building some kind of a newsreader app and wish to display the source of a news article in a proper way. Use the displayRootDomain method that takes url as input and gets the root domain and favicon.

This works for most URLs but I can’t guarantee if it will work for all links.

How to display the Application list of your publisher name in Windows phone app

We can easily use file and URI associations in Windows Phone 8 to directly launch the Windows app store so as to display the application list under your publisher name. A small example has been given below.



After calling the above function you will we get the following list as shown below.