0

I want to write an bandwidth speed test web app program.I used this method to test but it's only work perfectly fine for local host.Whene i upload my project to a web server,it doesn't work and give me access path denied because it tries to download and save the file on the webserver.I want to save this file on client machine.how can i fix this problem ?

    public ActionResult download()
    {

        Uri URL = new Uri("http://mylink/myfile.pdf");
        WebClient wc = new WebClient();
        double starttime = Environment.TickCount;
        wc.DownloadFile(URL, @"C:\speedtest.pdf");
        double endtime = Environment.TickCount;
        double secs = Math.Floor(endtime - starttime) / 1000;
        double secs2 = Math.Round(secs, 0);
        double kbsec = Math.Round(1024 / secs);
        test t = new test();
        try
        {
            System.IO.File.Delete("@C:\\speedtest.pdf");
            t.kbps = kbsec;
            t.message = "Done";
            t.rTime = secs2;
            t.time = secs;

        }
        catch
        {

            t.kbps = kbsec;
            t.message = "File not deleted";
            t.rTime = secs2;
            t.time = secs;
        }

        return Json(t);
    }
6
  • 1
    Of course it's downloading it on the server-side. Anything that's happening in your controller is happening on the web server. If you want to have it download the file on the client side, you'll need to write some client-side (e.g. JavaScript) code that handles it. Commented Aug 19, 2013 at 21:50
  • Can you guide me that how can i do this with java script ? Commented Aug 19, 2013 at 22:06
  • I would suggest looking at Visual Studio's 'Web Performance and Load Test' project template. I don't remember which version it comes with, but you might need Ultimate or Test Professional. Commented Aug 19, 2013 at 22:06
  • 2
    @paradise_human I'd recommend Google. If you have specific questions, post a new question here. Commented Aug 19, 2013 at 22:07
  • If you could just write to any user's hard disk at will that would be deeply unsecure. Commented Aug 19, 2013 at 22:53

1 Answer 1

1

wc.DownloadFile(URL, @"C:\speedtest.pdf");

ViewBag URL = speedtest.pdf;

send this file to view and then make the option to download these file

click to download

Sign up to request clarification or add additional context in comments.

1 Comment

You can use tilde wrappers to add code formatting to your answer. Three tildes and "C#" will format it multiline for C#.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.