Hello Everyone,
I am getting output in base64 format, I want to convert and download it into pdf and save to my local pc downloads folder.
I have converted that pdf to Bytes and tried to download using CreateDirectory method, but it downloads pdf to server's folder.
I am looking sample code in .net
Thanks in advance !!
Naimish MakwanaPosted Dec 3, 2024, 5:24 AM
Here's a sample code snippet in C# that converts a Base64 string to a PDF file and then downloads it to the user's Downloads folder using the
Responseproperty in an ASP.NET application:Explanation:
Convert.FromBase64Stringmethod converts the Base64 string to a byte array.context.Response.ContentTypeis set to "application/pdf" to indicate the type of file being sent.context.Response.AddHeadermethod sets the "Content-Disposition" header to "attachment" with a filename, prompting the browser to download the file.context.Response.BinaryWritemethod writes the byte array to the response.context.Response.Endmethod ends the response, ensuring the file is sent to the client.Usage:
This approach ensures the PDF is downloaded directly to the client's machine using the
Responseproperty.Thanks
Sushant TorankarPosted Dec 2, 2024, 4:23 PM
Hello Sangitha,
Thanks for reply.
I'll try your code and let you know
Sushant TorankarPosted Dec 2, 2024, 4:22 PM
Hello Jignesh,
Thanks for reply.
Your code looks like MVC based code, which does not work in c# asp.net . I am looking for a code in c# .net code. Which will convert base64 to pdf file and then download that pdf to DOWNLOADS folder using RESPONSE property.
Sangeetha SPosted Dec 2, 2024, 8:19 AM
Base64 String: Ensure that you have your PDF content as a Base64 string.
File Name: Specify the desired file name (e.g., "document.pdf").
Example
Jignesh KumarPosted Nov 30, 2024, 5:40 PM
Hello Shusant,
using the below code you can create a pdf from the base64String.
You can write client-side code to download,