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
- How to add two numbers in Android Studio? | Source Code
- FindViewByID returns null in android studio -SOLVED
- Saving changes is not permitted in SQL SERVER - [SOLVED]
- Restore of database failed. File cannot be restored over the existing. -[SOLVED]
- One or more projects in the solution were not loaded correctly in Visual Studio 2019 | FIXED
- How to find Laptop's Battery Health?
- SOLVED-Related Field got invalid lookup: icontains error in Django
- How to enable Search Feature in Django admin?
Related Article