Windows Phone Developers

Showing posts with label .NET Download Files. Show all posts
Showing posts with label .NET Download Files. Show all posts

Friday, April 9, 2010

How to Download File from Website using C# (.NET)

 How to Download File from Internet using C# (.NET)


private bool download_file_from_Net()

        {
            try
            {
                WebClient WC = new WebClient();
                String sWebLocation = "http://logic.stanford.edu/talks/Web2.0/microsoft-logo.jpg";
                String sLocalPath = "C:\\Temp\\New folder (2)\\microsoft-logo.jpg";
                WC.DownloadFile(sWebLocation, sLocalPath);
                return true;
            }

           catch (Exception ex1)
            {
                return false;
            }
        }
  



Following errors might occur if you do not use the Destination File Name

For example


                String sLocalPath = "C:\\Temp\\New folder (2)";


throws the following error
 InnerException = {"Access to the path 'C:\\Temp\\New folder (2)' is denied."}

and


                String sLocalPath = "C:\\Temp\\New folder (2)\\";



 throws the following one


System.Net.WebException was caught
  Message=An exception occurred during a WebClient request.
  InnerException: System.IO.DirectoryNotFoundException

       Message=Could not find a part of the path 'C:\Temp\New folder (2)\'.

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon