Example #1
2
 private void SendGETRequest(string url)
 {
     using (WebClient wc = new WebClient())
     {
         wc.DownloadStringAsync(new Uri(url));
     }
 }
    /// <summary>
    /// Retrieves the specified remote script using a WebClient.
    /// </summary>
    /// <param name="file">The remote URL</param>
    private static string RetrieveScript(string file)
    {
        string script = null;

        try
        {
            Uri url = new Uri(file, UriKind.Absolute);

            using (WebClient client = new WebClient())
            using (Stream buffer = client.OpenRead(url))
            using (StreamReader reader = new StreamReader(buffer))
            {
                script = StripWhitespace(reader.ReadToEnd());
                HttpContext.Current.Cache.Insert(file, script, null, Cache.NoAbsoluteExpiration, new TimeSpan(7, 0, 0, 0));
            }
        }
        catch (System.Net.Sockets.SocketException)
        {
            // The remote site is currently down. Try again next time.
        }
        catch (UriFormatException)
        {
            // Only valid absolute URLs are accepted
        }

        return script;
    }
Example #3
0
    static void Main()
    {
        Console.WriteLine(@"Problem 4. Download file
Write a program that downloads a file from Internet (e.g. Ninja image) 
and stores it the current directory.
Find in Google how to download files in C#.
Be sure to catch all exceptions and to free any used resources in the 
finally block.
============================================================================
Solution:");
        string sourceResource = "http://blogs.telerik.com/images/default-source/miroslav-miroslav/super_ninja.png?sfvrsn=2";
        string localFileName = Path.GetFileName(sourceResource);
        using (WebClient myWebClient = new WebClient())
        {
            try
            {
                Console.WriteLine("Start downloading {0}", sourceResource);
                myWebClient.DownloadFile(sourceResource, localFileName);
                Console.WriteLine("Download succesfull.");
                Console.WriteLine("You can see downloaded file in: local folder of this program\\bin\\Debug\\");
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
                if (ex.InnerException != null)
                    Console.WriteLine(" " + ex.InnerException.Message);
                else
                    Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something going wrong. Details: " + ex.Message);
            }
        }
    }
Example #4
0
 static void Main()
 {
     WebClient webClient = new WebClient();
     try
     {
         webClient.DownloadFile("http://www.devbg.org/img/Logo-BASD.jpg", @"C:\Users\Konstantin Iliev\Documents\txt.txt");
     }
     catch (ArgumentException ae)
     {
         Console.WriteLine("{0} - {1}", ae.GetType(), ae.Message);
     }
     catch (WebException webEx)
     {
         Console.WriteLine("{0} - {1}", webEx.GetType(), webEx.Message);
         Console.WriteLine("Destination not found!");
     }
     catch (NotSupportedException supportEx)
     {
         Console.WriteLine("{0} - {1}", supportEx.GetType(), supportEx.Message);
         Console.WriteLine(supportEx.Message);
     }
     catch (Exception allExp)
     {
         Console.WriteLine("{0} - {1}", allExp.GetType(), allExp.Message);
     }
 }
    /// <summary>
    /// Retrieve the URL that the client should redirect the user to to perform the OAuth authorization
    /// </summary>
    /// <param name="provider"></param>
    /// <returns></returns>
    protected override string GetAuthorizationUrl(String callbackUrl)
    {
        OAuthBase auth = new OAuthBase();
        String requestUrl = provider.Host + provider.RequestTokenUrl;
        Uri url = new Uri(requestUrl);
        String requestParams = "";
        String signature = auth.GenerateSignature(url, provider.ClientId, provider.Secret, null, null, provider.RequestTokenMethod ?? "POST",
            auth.GenerateTimeStamp(), auth.GenerateTimeStamp() + auth.GenerateNonce(), out requestUrl, out requestParams,
            new OAuthBase.QueryParameter(OAuthBase.OAuthCallbackKey, auth.UrlEncode(callbackUrl)));
        requestParams += "&oauth_signature=" + HttpUtility.UrlEncode(signature);
        WebClient webClient = new WebClient();
        byte[] response;
        if (provider.RequestTokenMethod == "POST" || provider.RequestTokenMethod == null)
        {
            response = webClient.UploadData(url, Encoding.ASCII.GetBytes(requestParams));
        }
        else
        {
            response = webClient.DownloadData(url + "?" + requestParams);
        }
        Match m = Regex.Match(Encoding.ASCII.GetString(response), "oauth_token=(.*?)&oauth_token_secret=(.*?)&oauth_callback_confirmed=true");
        String requestToken = m.Groups[1].Value;
        String requestTokenSecret = m.Groups[2].Value;
        // we need a way to save the request token & secret, so that we can use it to get the access token later (when they enter the pin)
        // just stick it in the session for now
        HttpContext.Current.Session[OAUTH1_REQUEST_TOKEN_SESSIONKEY] = requestToken;
        HttpContext.Current.Session[OAUTH1_REQUEST_TOKEN_SECRET_SESSIONKEY] = requestTokenSecret;

        return provider.Host + provider.UserApprovalUrl + "?oauth_token=" + HttpUtility.UrlEncode(requestToken);
    }
Example #6
0
    public string SendSms(List<string> mobiles)
    {
        using (var client = new WebClient())
        {
            try
            {
                string langCode = "1";
                if (Regex.IsMatch(Message, @"\p{IsArabic}+"))
                {
                    langCode = "2";
                }

                client.Headers.Add("content-type", "text/plain");
                string mobile=String.Join(",",mobiles.ToArray());
                string result = client.DownloadString(String.Format("http://brazilboxtech.com/api/send.aspx?username=smartksa&password=ksasmrt95647&language={0}&sender=NCSS&mobile={1}&message={2}",langCode, mobile, Message));
                if (result.StartsWith("OK"))
                {
                    return String.Empty;
                }
                return result;
            }
            catch (Exception ex)
            {

                return ex.Message;
            }

        }
    }
Example #7
0
    static void Main(string[] args)
    {
        /*     Write a program that downloads a file from Internet (e.g. Ninja image) and stores it in the current directory.
                   Find in Google how to download files in C#.
                   Be sure to catch all exceptions and to free any used resources in the finally block.*/

            Console.WriteLine("Enter Internet file address: "); // https://telerikacademy.com/Content/Images/news-img01.png
            string internetAddress = Console.ReadLine();
            string extension = internetAddress.Substring(internetAddress.LastIndexOf('.'), internetAddress.Length - internetAddress.LastIndexOf('.'));

            using (WebClient internetRover = new WebClient())
            {
                try
                {
                    Console.WriteLine("Recieving data...");
                    internetRover.DownloadFile(internetAddress, "downloadedFile" + extension);
                    Console.WriteLine("File successfully downloaded! File Location:...\\bin\\Debug");
                }
                catch (ArgumentNullException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (WebException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (NotSupportedException ex)
                {
                    Console.WriteLine(ex.Message);
                }

            }
    }
    static void Main()
    {
        WebClient webClient = new WebClient();
            using (webClient)
            {
                try
                {
                    webClient.DownloadFile("http://www.devbg.org/img/Logo-BASD.jpg", @"..\..\Logo-BASD.jpg");
                    //this row will be executed only if downwoad is successfull
                    Console.WriteLine("The file is downloaded");
                }
                catch (ArgumentNullException ex1)
                {
                    Console.WriteLine("{0}",ex1.Message);
                }
                catch (System.Net.WebException ex2)
                {
                    Console.WriteLine("{0}", ex2.Message);
                }
                catch (System.NotSupportedException ex3)
                {
                    Console.WriteLine("{0}", ex3.Message);
                }

            }
    }
 static void Main()
 {
     Console.WriteLine("Enter URI(adress) from where you will download: ");
     string url = Console.ReadLine();
     Console.WriteLine("Enter name for your file: ");
     string fileName = Console.ReadLine();
     //using  closes the resource after it`s work is done
     using (WebClient webClient = new WebClient())
     {
         try
         {
             webClient.DownloadFile(url, fileName);
             Console.WriteLine("Download complete!");
         }
         catch (ArgumentNullException)
         {
             Console.WriteLine("Either adress parameter is null or filename parameter is null!");
         }
         catch (WebException)
         {
             Console.WriteLine("The URI adress is invalid,filename is null or empty or an error occurred while downloading data!");
         }
         catch (NotSupportedException)
         {
             Console.WriteLine("The method has been called simultaneously on multiple threads.");
         }
         catch (ArgumentException)
         {
             Console.WriteLine("The path is not of a legal form.");
         }
     }
 }
Example #10
0
 public void method_0()
 {
     try
     {
         string xml;
         using (WebClient webClient = new WebClient())
         {
             xml = webClient.DownloadString(this.string_1 + "/main.xml");
         }
         XmlDocument xmlDocument = new XmlDocument();
         xmlDocument.LoadXml(xml);
         XmlNodeList elementsByTagName = xmlDocument.GetElementsByTagName("repofile");
         XmlNodeList elementsByTagName2 = ((XmlElement)elementsByTagName[0]).GetElementsByTagName("information");
         foreach (XmlElement xmlElement in elementsByTagName2)
         {
             XmlNodeList elementsByTagName3 = xmlElement.GetElementsByTagName("id");
             XmlNodeList elementsByTagName4 = xmlElement.GetElementsByTagName("name");
             this.string_0 = elementsByTagName4[0].InnerText;
             this.string_2 = elementsByTagName3[0].InnerText;
         }
         XmlNodeList elementsByTagName5 = ((XmlElement)elementsByTagName[0]).GetElementsByTagName("category");
         foreach (XmlElement xmlElement2 in elementsByTagName5)
         {
             XmlNodeList elementsByTagName3 = xmlElement2.GetElementsByTagName("id");
             XmlNodeList elementsByTagName4 = xmlElement2.GetElementsByTagName("name");
             GClass2 gClass = new GClass2();
             gClass.string_1 = elementsByTagName4[0].InnerText;
             gClass.string_0 = elementsByTagName3[0].InnerText;
         }
     }
     catch
     {
     }
 }
 static void Main()
 {
     string decorationLine = new string('-', 80);
     Console.Write(decorationLine);
     Console.WriteLine("***Downloading a file from Internet and storing it in the current directory***");
     Console.Write(decorationLine);
     WebClient webClient = new WebClient();
     try
     {
         string remoteUri = "http://www.telerik.com/images/newsletters/academy/assets/";
         string fileName = "ninja-top.gif";
         string fullFilePathOnWeb = remoteUri + fileName;
         webClient.DownloadFile(fullFilePathOnWeb, fileName);
         Console.WriteLine("Downloading '{0}' from {1} is completed!", fileName, remoteUri);
         Console.WriteLine("You can find it in {0}.", Environment.CurrentDirectory);
     }
     catch (ArgumentNullException)
     {
         Console.WriteLine("No file address is given!");
     }
     catch (WebException webException)
     {
         Console.WriteLine(webException.Message);
     }
     catch (NotSupportedException)
     {
         Console.WriteLine("Downloading a file is in process! Cannot download multiple \nfiles simultaneously!");
     }
     finally
     {
         webClient.Dispose();
     }
 }
    static void Main()
    {
        try
        {
            WebClient webClient = new WebClient();
            webClient.DownloadFile("http://www.devbg.org/img/Logo-BASD.jpg", @"C:\");
        }

        catch (ArgumentNullException)
        {
            Console.WriteLine("The address parameter is null.");
        }

        catch (WebException)
        {
            Console.Write("The URI formed by combining BaseAddress and address is invalid");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(" or ");
            Console.ResetColor();
            Console.Write("filename is null or Empty");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(" or ");
            Console.ResetColor();
            Console.Write("the file does not exist");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(" or ");
            Console.ResetColor();
            Console.WriteLine("an error occurred while downloading data.");
        }

        catch (NotSupportedException)
        {
            Console.WriteLine("The method has been called simultaneously on multiple threads.");
        }
    }
Example #13
0
    static void Main()
    {
        using (WebClient webClient = new WebClient())
        {
            try
            {
                Console.WriteLine("Starting to download...");
                webClient.DownloadFile("http://www.devbg.org/img/Logo-BASD.jpg", "../../Logo-BASD.jpg");
                Console.WriteLine("Downloaded!");
            }

            catch (WebException ex)
            {
                Console.Error.WriteLine("Sorry, there was an error!" + ex.Message);
            }
            catch (ArgumentNullException ex)
            {
                Console.Error.WriteLine("Sorry, you didn't enter anything!" + ex.Message);
            }
            catch (NotSupportedException ex )
            {
                Console.Error.WriteLine("Sorry, there was an error!" + ex.Message);
            }
        }
    }
Example #14
0
 static void Main()
 {
     try
     {
         WebClient webClient = new WebClient();
         webClient.DownloadFile("http://telerikacademy.com/Content/Images/news-img01.png", "news-img01.png");
         Console.WriteLine("You can find the downloaded image in 'bin' directory of the project.");
     }
     catch (ArgumentException ex)
     {
         Console.WriteLine(ex.Message);
     }
     catch (WebException ex)
     {
         Console.WriteLine(ex.Message);
     }
     catch (NotSupportedException ex)
     {
         Console.WriteLine(ex.Message);
     }
     catch (UnauthorizedAccessException ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
    // Write a program that downloads a file from Internet
    // (e.g. http://www.devbg.org/img/Logo-BASD.jpg) and
    // stores it the current directory. Find in Google how 
    // to download files in C#. Be sure to catch all exceptions
    // and to free any used resources in the finally block.

    static void Main()
    {
        WebClient client = new WebClient();
        using (client)
        {
            try
            {
                client.DownloadFile("http://academy.telerik.com/images/default-album/telerik-academy-banner-300x250.jpg?sfvrsn=2",
                            "../../../telerik-academy-banner-300x250.jpg");
            }
            catch (WebException we)
            {
                Console.Error.WriteLine("File is inaccessible!" + we.Message);
            }

            catch (NotSupportedException ne)
            {
                Console.Error.WriteLine("Ooops something went wrong!" + ne.Message);
            }
            catch (ArgumentNullException ae)
            {
                Console.Error.WriteLine("Ooops something went wrong!" + ae.Message);
            }
        }
    }
 static void Main()
 {
     Console.WriteLine("Enter the URL that you wish to download.");
     Console.Write("URL: ");
     string url = Console.ReadLine();
     Console.WriteLine("Directory to download to:");
     string directory = Console.ReadLine();
     try
     {
         WebClient request = new WebClient();
         using (request)
         {
             request.DownloadFile(url, directory);
         }
     }
     catch (ArgumentNullException)
     {
         Console.WriteLine("The url does not exist or it was not entered.");
     }
     catch (ArgumentException)
     {
         Console.WriteLine("Invalid input data.");
     }
     catch (WebException)
     {
         Console.WriteLine("You do not have privileges to download / Problem with internet connection.");
     }
     catch (NotSupportedException)
     {
         Console.WriteLine("Error 404: File not found!");
     }
 }
        public static void ProcessQueueMessage([ServiceBusTrigger("resizepicturesqueue")] ResizePictureMessage message, TextWriter logger)
        {
            var azureStorageConnectionString = ConfigurationManager.ConnectionStrings["AzureStorage"].ConnectionString;

            byte[] data;
            using (var client = new WebClient())
            {
                data = client.DownloadData(message.PictureReference);
            }

            var tumbnail = ImageResizer.CreateTumbnail(Image.FromStream(new MemoryStream(data)));

            var storageAccount = CloudStorageAccount.Parse(azureStorageConnectionString);
            var filesStorageService = new FilesStorageService(storageAccount);

            var uploadedFileUrl = filesStorageService.UploadFile(Guid.NewGuid().ToString(), tumbnail).Result;

            using (var context = new ConstructionsProgressTrackerContext())
            {
                context.ProgressTrackingEntries.Single(e => e.Id == message.Id).TumbnailPictureReference = uploadedFileUrl;
                context.SaveChanges();
            }

            logger.WriteLine($"Tumbnail for entry:{message.Id} successfully created.");
        }
    static void Main()
    {
        try
        {
            string url = "http://www.devbg.org/img/";
            string fileName = "Logo-BASD.jpg", myDownload = null;

            WebClient downloader = new WebClient();

            myDownload = url + fileName;
            Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myDownload);

            downloader.DownloadFile(myDownload, fileName);
            Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, url);
            Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);
        }
        catch (ArgumentException)
        {
            Console.WriteLine("There is a problem with the url or file name format entered");
        }

        catch (WebException)
        {
            Console.WriteLine("Combinig the url and filename is invalid or an error occured while downloading data.");
        }
        catch (SecurityException)
        {
            Console.WriteLine("Permission writing issues.");
        }
    }
Example #19
0
        public static void Properties_InvalidArguments_ThrowExceptions()
        {
            var wc = new WebClient();

            Assert.Throws<ArgumentException>("value", () => { wc.BaseAddress = "http::/invalid url"; });
            Assert.Throws<ArgumentNullException>("Encoding", () => { wc.Encoding = null; });
        }
    static void Main()
    {
        string remoteUri = "http://telerikacademy.com/Content/Images/";
        string fileName = "news-img01.png";
        string webResource = null;
        WebClient myWebClient = new WebClient();
        webResource = remoteUri + fileName;


        Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n", fileName, webResource);
        try
        {
            myWebClient.DownloadFile(webResource, fileName);
            Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, webResource);
        }
        catch (ArgumentNullException)
        {
            Console.WriteLine("No address given.");
        }
        catch (WebException)
        {
            Console.WriteLine("The file does not exist or the name is empty.");
        }
        catch (NotSupportedException)
        {
            Console.WriteLine("The method has been called simultaneously on multiple threads.");
        }
        finally
        {
            myWebClient.Dispose();
        }
        Console.WriteLine();
    }
Example #21
0
    static void Main()
    {
        using (WebClient web = new WebClient())
        {
            try
            {
                // Download and save the file
                web.DownloadFile("http://www.devbg.org/img/Logo-BASD.jpg", @"D:\Logo-BASD.jpg");
            }
            catch (WebException)
            {
                Console.WriteLine("An error occurred while downloading data, or the file does not exist.");
            }
            catch (NotSupportedException)
            {
                Console.WriteLine("The method has been called simultaneously on multiple threads.");
            }

            Console.Write("[Done] The file is saved in 'D:\\'" + Environment.NewLine +
                              " Open file? [Y/N]: ");

            // open file option
            switch (Console.ReadLine().ToLower())
            {
                case "y": OpenFile(); break;
                default: return;
            }
        }
    }
    static void Main()
    {
      using (WebClient downloadClient = new WebClient())
        {
            try
            {
                Console.WriteLine("Downloading..");
                downloadClient.DownloadFile("http://telerikacademy.com/Content/Images/news-img01.png", "news-img01.png");
                Console.WriteLine("Image was downloaded successfully in 'bin' directory of the project!");
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (WebException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (NotSupportedException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.WriteLine("Goodbye!");
            }
        }

    }
Example #23
0
 static void Main()
 {
     WebClient webClient = new WebClient();
         try
         {
             webClient.DownloadFile("http://telerikacademy.com/Content/Images/news-img01.png", @"news-img01.png");
             Console.WriteLine("Done"); // image is downloaded in your current directory.
         }
         catch (ArgumentNullException)
         {
             Console.WriteLine("The address parameter is null");
         }
         catch (WebException)
         {
             Console.WriteLine("File does not exist, its name is null or empty, address is invalid, or an error occurred while downloading data");
         }
         catch (NotSupportedException)
         {
             Console.WriteLine("The method has been called simultaneously on multiple threads");
         }
         finally
         {
             webClient.Dispose();
         }
 }
    static void Main()
    {
        WebClient webClient = new WebClient();
        string linkToFile = @"http://www.devbg.org/img/Logo-BASD.jpg";
        try
        {
            webClient.DownloadFile( linkToFile,"logo.jpg");
        }

        catch (ArgumentNullException)
        {
            Console.WriteLine("You can't use null arguments");
        }
        catch (ArgumentException)
        {
            Console.WriteLine("'{0}' is a wrong path", linkToFile);
        }
        catch (NotSupportedException)
        {
            Console.WriteLine("Use different slashes for this operating system");
        }
        catch (WebException)
        {
            Console.WriteLine("Not file specified to save to");
        }
        finally
        {
            webClient.Dispose();
        }
    }
Example #25
0
    static void Download(string url, string downloadDir)
    {
        try
        {
            WebClient client = new WebClient();

            using (client)
            {
                client.DownloadFile(url, downloadDir);
            }

            Console.WriteLine("The file was successfully downloaded!!!");
        }
        catch (ArgumentNullException)
        {
            Console.Error.WriteLine("Missing url or download directory!!!");
        }
        catch (WebException)
        {
            Console.Error.WriteLine("You have entered a wrong url or you have not set a name for the file!!!");
        }
        catch (NotSupportedException)
        {
            Console.Error.WriteLine("The application can not download the file!!!");
        }
    }
Example #26
0
    protected void btnGetLoc_Click(object sender, EventArgs e)
    {
        WebClient wc = new WebClient();
        Stream data = wc.OpenRead(String.Format("http://iplocationtools.com/ip_query2.php?ip={0}", txtIP.Text.Trim()));
        String str;
        using (StreamReader sr = new StreamReader(data))
        {
            str = sr.ReadToEnd();
            data.Close();
        }
        //String url = String.Empty;

        //if (txtIP.Text.Trim() != String.Empty)
        //{
        //    url = String.Format("http://iplocationtools.com/ip_query2.php?ip={0}", txtIP.Text.Trim());
        //    XDocument xDoc = XDocument.Load(url);
        //    if (xDoc == null | xDoc.Root == null)
        //    {
        //        throw new ApplicationException("Data is not Valid");
        //    }

        //    Xml1.TransformSource = "IP.xslt";
        //    Xml1.DocumentContent = xDoc.ToString();
        //}
    }
Example #27
0
    private void GetUpdateList(string updateKey)
    {
        WebClient client = new WebClient();
        client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";

        string response;

        try
        {
            response = client.UploadString("http://infinity-code.com/products_update/checkupdates.php",
            "k=" + WWW.EscapeURL(updateKey) + "&v=" + OnlineMaps.version + "&c=" + (int)channel);
        }
        catch
        {
            return;
        }
        
        XmlDocument document = new XmlDocument();
        document.LoadXml(response);

        XmlNode firstChild = document.FirstChild;
        updates = new List<OnlineMapsUpdateItem>();

        foreach (XmlNode node in firstChild.ChildNodes) updates.Add(new OnlineMapsUpdateItem(node));
    }
    static void Main()
    {
        Console.Write("Enter URL address: ");
        string path = Console.ReadLine();

        Console.Write("Enter file name: ");
        string name = Console.ReadLine();

        using (WebClient webClient = new WebClient())
        {
            try
            {
                using (WebClient Client = new WebClient())
                {
                    Client.DownloadFile(path, name);
                }
            }
            catch (ArgumentException)
            {
                Console.WriteLine("The path is zero-length/ one or more invalid chars!");
            }
            catch (WebException)
            {
                Console.WriteLine("Invalid address/ filename-null reference(empty)/ error while downloading!");
            }
            catch (System.Security.SecurityException)
            {
                Console.WriteLine("You do not have the required permission to write to local file!");
            } 
        }
    }
 static void Main()
 {
     try
     {
         string uri = "http://www.devbg.org/img/";
         string fileName = "Logo-BASD.jpg";
         string WebResource = null;
         WebClient myWebClient = new WebClient();
         WebResource = uri + fileName;
         Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, WebResource);
         myWebClient.DownloadFile(WebResource, fileName);
         Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, WebResource);
         Console.WriteLine("\nDownloaded file saved in the current file system(bin) folder");
     }
     catch (ArgumentNullException)
     {
         Console.WriteLine("Invalid file");
     }
     catch (WebException)
     {
         Console.WriteLine("No network access");
     }
     catch (NotSupportedException)
     {
         Console.WriteLine("Method is not supported");
     }
 }
 static void Main()
 {
     using (WebClient webCl = new WebClient())
     {
         try
         {
             Console.WriteLine("Write a program that downloads a file from Internet (e.g. http://www.devbg.org/img/Logo-BASD.jpg) and stores it the current directory. Find in Google how to download files in C#. Be sure to catch all exceptions and to free any used resources in the finally block.");
             Console.WriteLine();
             webCl.DownloadFile("http://www.devbg.org/img/Logo-BASD.jpg", "image.jpg");
             Console.WriteLine("Download Complete.");
         }
         catch (System.Net.WebException)
         {
             Console.WriteLine("Error downloading file.");
         }
         catch (System.ArgumentException)
         {
             Console.WriteLine("Wrong path");
         }
         finally
         {
             webCl.Dispose();
         }
     }
 }