Download File From URL In ASP.Net Using C# And VB.Net
Có thể bạn quan tâm
حضرت خواجہ سیدنا معین الدین حسن چشتی سنجاری اجمیری رحمۃ اللہ علیہ
- HOME
- BLOGS
- ASP.Net C#.Net JavaScript ADO.Net Excel AJAX VB.Net SQL Server GridView Issues and Exceptions Silverlight Rich Text Editor jQuery DataList Snippets XML New Features .Net 4.0 TreeView AJAX Control Toolkit jQuery Plugins Third Party Controls ASP.Net Validators WCF Repeater Regular Expressions Yahoo API iTextSharp FaceBook Charts ListView Tweeter Google CSS SMS DotNetZip Crystal Reports Entity Framework HyperLink RDLC Report SqlDataSource Menu YouTube Twitter HTML XmlDataSource ListBox Tips DataGridView Cryptography Windows Forms LinkedIn WebUserControl RSS Feeds HTML5 Sitemap IIS LINQ DataPager URL Routing SqlBulkCopy OCR ASP.Net 4.5 Master Pages MySQL CSV Stored Procedures JSON Web Services Bootstrap Windows Service DataTable App.Config Visual Studio RadioButton CheckBox Generic Handler DropDownList FileUpload RadioButtonList CheckBoxList Flash HtmlEditorExtender Div Table AngularJS DataReader DataSet Console Applications FTP DetailsView Password TextBox Enum ComboBox Sponsored SqlDataAdapter OpenXml ClosedXml SiteMapPath Arrays FormView
- FORUMS
- Questions
- Ask Question
- VIDEOS
-
- SEARCH
- INTERVIEW
- Interview Questions
- COMMUNITY
- Users
- CONTACT
fr3eddy - SOLVED
- User: fr3eddy
- Posted: on Apr 18, 2018 11:58 PM
- Forum: ASP.Net Web Forms
- Answer: 1
- Views: 28393
i need to download 1 file from my database i use this but i don't know what is missign this doesnt work
database bl = new database(); var url = JsonConvert.SerializeObject(bl.getViewDocument(in_master_do_id, in_do_id, in_doc_type, in_view_type)); Stream stream = null; int bytesToRead = 10000; var fileName = "test"; byte[] buffer = new Byte[bytesToRead]; try { HttpWebRequest urlRequest = (HttpWebRequest)HttpWebRequest.Create(url); HttpWebResponse urlResponse = (HttpWebResponse)urlRequest.GetResponse(); if (urlRequest.ContentLength > 0) urlResponse.ContentLength = urlRequest.ContentLength; stream = urlResponse.GetResponseStream(); var resp = HttpContext.Current.Response; resp.ContentType = "application/octet-stream"; resp.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); resp.AddHeader("Content-Length", urlResponse.ContentLength.ToString()); } finally { if (stream != null) { stream.Close(); } } //return JsonConvert.SerializeObject(bl.getViewDocument(in_master_do_id, in_do_id, in_doc_type, in_view_type)); return url;
kalpesh 0 1 - Reply
- ANSWER
- User: kalpesh
- Replied: on Apr 19, 2018 12:28 AM
- Modified: on Apr 19, 2018 12:41 AM
- Report
You can refer below link for your reference also you can refer below sample code for your reference.
How to convert any URL to Image in ASP.Net
Refer the below sample code for your reference.
C#
protected void Page_Load(object sender, EventArgs e) { System.Net.WebClient webClient = new System.Net.WebClient(); string url = "https://static.flickr.com/66/199481236_dc98b5abb3_s.jpg"; byte[] bytes = webClient.DownloadData(url); string fileName = (url.Split('/')[url.Split('/').Length - 1]).Split('.')[0]; Response.ContentType = "image/png"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); Response.BinaryWrite(bytes); Response.End(); }VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim webClient As System.Net.WebClient = New System.Net.WebClient() Dim url As String = "https://static.flickr.com/66/199481236_dc98b5abb3_s.jpg" Dim bytes As Byte() = webClient.DownloadData(url) Dim fileName As String = (url.Split("/"c)(url.Split("/"c).Length - 1)).Split("."c)(0) Response.ContentType = "image/png" Response.AppendHeader("Content-Disposition", "attachment; filename=" & fileName) Response.BinaryWrite(bytes) Response.[End]() End SubScreenshot

Company
- About us
- Contact us
Explore
- Ask question
- FAQs
- Privacy policy
Follow us
- YouTube
Contact Us
- Email: [email protected]
- Address: ASPSNIPPETS PRIVATE LIMITED G-110, SHAGUN ARCADE, MALAD (EAST), MUMBAI, MAHARASHTRA, INDIA 400097.
© COPYRIGHT 2026 ASPSnippets.com ALL RIGHTS RESERVED.
Disclaimer This site makes use of Cookies. Please refer Privacy Policy for more details. Allow RejectTừ khóa » Visual Basic Download File From Url
-
Download File From URL Code VB.NET - Stack Overflow
-
How To: Download A File - Visual Basic | Microsoft Docs
-
Visual Basic Code Snippet - Download File From URL
-
HowTo: Download A File From The Web And Save It With An ... - VB Helper
-
How To Download File Using Url To Local Pc In VB.NET - CodeProject
-
Thread: Best Way To Download Files - VBForums
-
Visual Basic .NET Tutorial 37 - How To Download A File In VB.NET
-
How To Download Files/Data In Visual Studio - YouTube
-
Thread: Download File From URL - CodeGuru Forums
-
Download A File From The Internet (without A Prompt Dialog)
-
Visual Basic 6.0 SharePoint -- Download File - Chilkat Examples
-
Download File From URL – Visual C++/CLI Development - Skanky
-
Download A File From Url Using VBA
-
Command Line Interface (CLI) - Visual Studio Code