ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Create WebService to read PDF from folder and download using C# and VB.Net in ASP.Net<p>Hi <a class="username" rel="pvermacs"> pvermacs</a>,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p>I have created a web service that return base64String.</p> <p><strong><span style="text-decoration: underline;">PDFService</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">[WebMethod] public string GetData() { string path = Server.MapPath(&#34;~/Files/Test.pdf&#34;); byte[] bytes = System.IO.File.ReadAllBytes(path); return Convert.ToBase64String(bytes); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">&lt;WebMethod&gt; Public Function GetData() As String Dim path As String = Server.MapPath(&#34;~/Files/Test.pdf&#34;) Dim bytes As Byte() = System.IO.File.ReadAllBytes(path) Return Convert.ToBase64String(bytes) End Function</pre> <p>Acccessing the service in page.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;asp:LinkButton Text=&#34;Download&#34; runat=&#34;server&#34; OnClick=&#34;Download&#34; /&gt;</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Download(object sender, EventArgs e) { PDFService service = new PDFService(); string base64String = service.GetData(); byte[] bytes = Convert.FromBase64String(base64String); System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes); Response.Clear(); Response.Buffer = true; Response.ContentType = &#34;application/pdf&#34;; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment;filename=Test.pdf&#34;); ms.WriteTo(Response.OutputStream); Response.End(); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Download(ByVal sender As Object, ByVal e As EventArgs) Dim service As PDFService = New PDFService() Dim base64String As String = service.GetData() Dim bytes As Byte() = Convert.FromBase64String(base64String) Dim ms As IO.MemoryStream = New IO.MemoryStream(bytes) Response.Clear() Response.Buffer = True Response.ContentType = &#34;application/pdf&#34; Response.AddHeader(&#34;content-disposition&#34;, &#34;attachment;filename=Test.pdf&#34;) ms.WriteTo(Response.OutputStream) Response.[End]() End Sub</pre> <p>On the Download button click pdf file will be downloaded.</p>https://www.aspforums.net:443/Threads/112991/Create-WebService-to-read-PDF-from-folder-and-download-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/112991/Create-WebService-to-read-PDF-from-folder-and-download-using-C-and-VBNet-in-ASPNet/Sat, 03 Feb 2018 07:08:22 GMT