{"id":23002,"date":"2021-03-23T13:41:42","date_gmt":"2021-03-23T17:41:42","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/file-downloading-in-c-applications-root-by-sayed-ahmed\/"},"modified":"2025-05-11T20:19:39","modified_gmt":"2025-05-11T20:19:39","slug":"file-downloading-in-c-applications-root-by-sayed-ahmed","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=23002","title":{"rendered":"File Downloading in C# Applications #Root #By Sayed Ahmed"},"content":{"rendered":"<p>For ASP.Net web form applications, you can use [for file download]<\/p>\n<h2>Synchronously<\/h2>\n<pre class=\"code\"><span class=\"keyword\">\r\nusing<\/span> System.Net;\r\n\r\n<span class=\"type\">WebClient<\/span> webClient = <span class=\"keyword\">new<\/span> <span class=\"type\">WebClient<\/span>();\r\nwebClient.<strong>DownloadFile<\/strong>(<span class=\"string\">\"http:\/\/mysite.com\/myfile.txt\"<\/span>, <span class=\"string\">@\"c:myfile.txt\"<\/span>);\r\n\r\nor\r\n\r\n<\/pre>\n<h2>Asynchronously<\/h2>\n<pre class=\"code\"><span class=\"keyword\">private void<\/span> btnDownload_Click(<span class=\"keyword\">object<\/span> sender, <span class=\"type\">EventArgs<\/span> e)\r\n{\r\n  <span class=\"type\">WebClient<\/span> webClient = <span class=\"keyword\">new<\/span> <span class=\"type\">WebClient<\/span>();\r\n  webClient.DownloadFileCompleted += <span class=\"keyword\">new<\/span> <span class=\"type\">AsyncCompletedEventHandler<\/span>(Completed);\r\n  webClient.DownloadProgressChanged += <span class=\"keyword\">new<\/span> <span class=\"type\">DownloadProgressChangedEventHandler<\/span>(ProgressChanged);\r\n  webClient.<strong>DownloadFileAsync<\/strong>(<span class=\"keyword\">new<\/span> <span class=\"type\">Uri<\/span>(<span class=\"string\">\"http:\/\/mysite.com\/myfile.txt\"<\/span>), <span class=\"string\">@\"c:myfile.txt\"<\/span>);\r\n}\r\n\r\n<span class=\"keyword\">private void<\/span> ProgressChanged(<span class=\"keyword\">object<\/span> sender, <span class=\"type\">DownloadProgressChangedEventArgs<\/span> e)\r\n{\r\n  progressBar.Value = e.ProgressPercentage;\r\n}\r\n\r\n<span class=\"keyword\">private void<\/span> Completed(<span class=\"keyword\">object<\/span> sender, <span class=\"type\">AsyncCompletedEventArgs<\/span> e)\r\n{\r\n  <span class=\"type\">MessageBox<\/span>.Show(<span class=\"string\">\"Download completed!\"<\/span>);\r\n}\r\n\r\n--\r\nAnother Simple Approach : When you are using Ajax or Web-Service in Ajax style (.asmx), this will be handy though will expose the file path. For publicly open applications use it with care and take required security pre-cautions.\r\n\r\nuse the regular anchor tag with download attribute.<\/pre>\n<pre class=\"code\"><\/pre>\n<p> From: http:\/\/sitestree.com\/?p=1845<br \/> Categories:Root, By Sayed Ahmed<br \/>Tags:<br \/> Post Data:2014-12-30 21:01:31<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For ASP.Net web form applications, you can use [for file download] Synchronously using System.Net; WebClient webClient = new WebClient(); webClient.DownloadFile(&#8220;http:\/\/mysite.com\/myfile.txt&#8221;, @&#8221;c:myfile.txt&#8221;); or Asynchronously private void btnDownload_Click(object sender, EventArgs e) { WebClient webClient = new WebClient(); webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); webClient.DownloadFileAsync(new Uri(&#8220;http:\/\/mysite.com\/myfile.txt&#8221;), @&#8221;c:myfile.txt&#8221;); } private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e) { progressBar.Value &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=23002\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1973,1917],"tags":[],"class_list":["post-23002","post","type-post","status-publish","format-standard","hentry","category-c-misc","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":26597,"url":"http:\/\/bangla.sitestree.com\/?p=26597","url_meta":{"origin":23002,"position":0},"title":"WebClient &#8211; Client application that can talk interactively to Web servers. Requires the components listed below #Programming Code Examples #Java\/J2EE\/J2ME #Network Programming","author":"Author-Check- Article-or-Video","date":"April 29, 2021","format":false,"excerpt":"WebClient - Client application that can talk interactively to Web servers. Requires the components listed below import java.awt.*; \/\/ For BorderLayout, GridLayout, Font, Color. import java.awt.event.*; import java.util.*; import javax.swing.*; \/** A graphical client that lets you interactively connect to * Web servers and send custom request lines and *\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10198,"url":"http:\/\/bangla.sitestree.com\/?p=10198","url_meta":{"origin":23002,"position":1},"title":"WebClient &#8211; Client application that can talk interactively to Web servers. Requires the components listed below","author":"","date":"August 25, 2015","format":false,"excerpt":"import java.awt.*; \/\/ For BorderLayout, GridLayout, Font, Color. import java.awt.event.*; import java.util.*; import javax.swing.*; \/** A graphical client that lets you interactively connect to \u00a0*\u00a0 Web servers and send custom request lines and \u00a0*\u00a0 request headers. \u00a0* \u00a0*\u00a0 Taken from Core Web Programming from \u00a0*\u00a0 Prentice Hall and Sun Microsystems\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70283,"url":"http:\/\/bangla.sitestree.com\/?p=70283","url_meta":{"origin":23002,"position":2},"title":"Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"August 31, 2021","format":false,"excerpt":"Brought from: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1319&title=Random%20Notes%20and%20simple%20code%20on%20Developing%20Web%20Sites%20(Applications)%20in%20ASP.net%20using%20C# And sure, pretty old article.. Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# The information below primarily apply to the web page model of web-development in C# _PageStart.cshtml runs at each page start\/open _AppStart.cshtml runs at the beginning of the application\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70303,"url":"http:\/\/bangla.sitestree.com\/?p=70303","url_meta":{"origin":23002,"position":3},"title":"Creating your own Classes in C# in ASP.net #.Net Web Applications","author":"Author-Check- Article-or-Video","date":"September 1, 2021","format":false,"excerpt":"Brought from our old site: http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=1348&title=Creating%20your%20own%20Class%20in%20C#%20in%20ASP.net Creating your own Class in C# in ASP.net It is kind of simple. You need to create a class library. The class library will create a dll file. From your project, you need to add reference to the dll file. Then you will be\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":69882,"url":"http:\/\/bangla.sitestree.com\/?p=69882","url_meta":{"origin":23002,"position":4},"title":"Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# #19","author":"Author-Check- Article-or-Video","date":"August 21, 2021","format":false,"excerpt":"Random Notes and simple code on Developing Web Sites (Applications) in ASP.net using C# The information below primarily apply to the web page model of web-development in C# _PageStart.cshtml runs at each page start\/open _AppStart.cshtml runs at the beginning of the application Syntax to use the Layout file: @{Layout =\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65654,"url":"http:\/\/bangla.sitestree.com\/?p=65654","url_meta":{"origin":23002,"position":5},"title":"XML Related Classes in .Net #Misc .Net","author":"Author-Check- Article-or-Video","date":"July 10, 2021","format":false,"excerpt":"Brought from our old site (yes, very old short-note): http:\/\/salearningschool.com\/displayArticle.php?table=Articles&articleID=633&title=XML%20Related%20Clasees%20in%20.Net XML in ADO.net VB.NET C#.NET XML is the foundation of .NET. .NET internally represents data as XML and hence can provide inter-operability and interaction among applications written in different platforms and languages [.Net compatible]. XmlReader In .Net you can use\u2026","rel":"","context":"In &quot;C# - Misc&quot;","block_context":{"text":"C# - Misc","link":"http:\/\/bangla.sitestree.com\/?cat=1973"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/23002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=23002"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/23002\/revisions"}],"predecessor-version":[{"id":78139,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/23002\/revisions\/78139"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=23002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=23002"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=23002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}