Hi pvermacs,
Check this example. Now please take its reference and correct your code.
I have created a web service that return base64String.
PDFService
C#
[WebMethod]
public string GetData()
{
string path = Server.MapPath("~/Files/Test.pdf");
byte[] bytes = System.IO.File.ReadAllBytes(path);
return Convert.ToBase64String(bytes);
}
VB.Net
<WebMethod>
Public Function GetData() As String
Dim path As String = Server.MapPath("~/Files/Test.pdf")
Dim bytes As Byte() = System.IO.File.ReadAllBytes(path)
Return Convert.ToBase64String(bytes)
End Function
Acccessing the service in page.
HTML
<asp:LinkButton Text="Download" runat="server" OnClick="Download" />
Code
C#
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 = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Test.pdf");
ms.WriteTo(Response.OutputStream);
Response.End();
}
VB.Net
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 = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=Test.pdf")
ms.WriteTo(Response.OutputStream)
Response.[End]()
End Sub
On the Download button click pdf file will be downloaded.