In this article I will show you how to create a web application to check the speed of downloading files in asp.net c#.
You can find out the time required to download a file. Here I used to download a jQuery script file from Google CDN and calculate the speed based on the download start and end time.
DownloadSpeed.aspx:
<form id="form1" runat="server">
<div style="border: 1px solid #357ae8; padding:15px 15px 15px 15px ; width: 400px; height: 250px">
<h2>Monitoringdownload speed of file </h2>
<asp:Label ID="lblDownloadSpeed" runat="server" />
<asp:Button ID="btnCheckSpeed" Text="Check Speed" runat="server" OnClick="DownloadSpeed" />
</div>
</form>
Code Behind DownloadSpeed.aspx.cs:
protected void DownloadSpeed(object sender, EventArgs e)
{
double[] speeds = new double[5];
for (int i = 0; i < 5;i++)
{
int jQueryFileSize = 261; //Size of google cdn JQuery File in KB.
WebClient client = new WebClient();
DateTime startTime = DateTime.Now;
client.DownloadFile("http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js", Server.MapPath("~/jQuery.js"));
DateTime endTime = DateTime.Now;
speeds[i] = Math.Round((jQueryFileSize / (endTime- startTime).TotalSeconds));
}
lblDownloadSpeed.Text = string.Format("Download Speed:{0}KB/s",speeds.Average());
}
Output:
Post your comments / questions
Recent Article
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
- The request was aborted: Could not create SSL/TLS secure channel -Error in Asp.net
- FieldError: Cannot resolve keyword 'id' into field in Django project
Related Article