Here is the code snippet to check your internet connection speed (download speed).
Add namespace
using System.Net;
Write code in a Web application on a button click event handler.
- Uri URL = new Uri("http://sixhoej.net/speedtest/1024kb.txt");
- WebClient wc = new WebClient();
- double starttime = Environment.TickCount;
-
- wc.DownloadFile(URL, @"C:\speedtest.txt");
-
- double endtime = Environment.TickCount;
-
-
-
- double secs = Math.Floor(endtime - starttime) / 1000;
-
- double secs2 = Math.Round(secs, 0);
-
-
-
- double kbsec = Math.Round(1024 / secs);
- Label1.Text = "Download rate: " + kbsec + " kb/sec";
- try
- {
-
- System.IO.File.Delete(@"C:\speedtest.txt");
- Response.Write("Done.");
- }
- catch
- {
- Response.Write("Couldn't delete download file.");
- Response.Write("To delete the file yourself, go to your C-drive and look for the file 'speedtest.txt'.");
- }