Download File From URL In ASP.Net Using C# And VB.Net

logo حضرت خواجہ سیدنا معین الدین حسن چشتی سنجاری اجمیری رحمۃ اللہ علیہ logo
  • 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
  • Click to Login.
Search Ask Question Download file from URL in ASP.Net using C# and VB.Net fr3eddy fr3eddy
  • SOLVED CLOSED ACTIVE ANSWERED
  • 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; Download FREE API for Word, Excel and PDF in ASP.Net kalpesh 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 Sub

Screenshot

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html Ask Question Image

Company

  • About us
  • Contact us

Explore

  • Ask question
  • FAQs
  • Privacy policy

Follow us

  • Facebook
  • Instagram
  • YouTube
  • Twitter

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 Reject

Từ khóa » Visual Basic Download File From Url