3
Answers

Importing remote http excel file as datasource?

Photo of Michael Reid

Michael Reid

15y
3.7k
1
Hi, Firstly I'm new. New to everything... including this forum, programming in C#, object orientated programming as a concept and indeed visual studio. Last week I built my first C# windows form program, basically reading information from a MySql database and organising it into several Listviews with certain controls. Now I'm trying something different which the last hour of Googling hasn't helped with. There is a remotely stored excel file (CSV) which I want to read from a Windows Form and eventually upload to a MySql database. I think I should be ok with the upload part, it's remotely connecting to this file and getting initial parsing of the data which is the issue. I've been succesful in configuring a local excel file on my machine as a datasource through the Visual Studio interface but have drawn a blank when trying to do it remotely. Any one any tips or ideas? P.S. I will come back with silly questions later, go easy.

Answers (3)

0
Photo of Dinesh Ambaliya
NA 42 59.8k 11y
Thanks you for your code and also I found useful Net.NetworkInformation namespace and its classes for my application. Thanks!
0
Photo of Pankaj Pandey
NA 6.3k 1.1m 11y
hello


you can try it



 Uri URL = new Uri("http://sixhoej.net/speedtest/1024kb.txt");
        WebClient wc = new WebClient();
        double starttime = Environment.TickCount;

        // download file from the specified URL, and save it to C:\speedtest.txt
        wc.DownloadFile(URL, @"C:\speedtest.txt");

        // get current tickcount
        double endtime = Environment.TickCount;

        // how many seconds did it take?
        // we are calculating this by subtracting starttime from endtime
        // and dividing by 1000 (since the tickcount is in miliseconds.. 1000 ms = 1 sec)
        double secs = Math.Floor(endtime - starttime) / 1000;

        // round the number of secs and remove the decimal point
        double secs2 = Math.Round(secs, 0);

        // calculate download rate in kb per sec.
        // this is done by dividing 1024 by the number of seconds it
        // took to download the file (1024 bytes = 1 kilobyte)
        double kbsec = Math.Round(1024 / secs);
        Label1.Text = "Download rate: " + kbsec + " kb/sec";
        try
        {
            // delete downloaded file
            System.IO.File.Delete(@"C:\speedtest.txt");
            Console.WriteLine("Done.");
        }
        catch
        {
            Console.WriteLine("Couldn't delete download file.");
            Console.WriteLine("To delete the file yourself, go to your C-drive and look for the file 'speedtest.txt'.");
            Console.ReadKey();
        }