[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

pass byte array from C# to Javascript and convert that byte array to PDF and save it in client machine.

Posted on 2010-03-30
2
Medium Priority
?
2,281 Views
Last Modified: 2012-06-27
1. I get blob data in C#.
2. I convert that blob data to byte[] array.
3. I want to pass that byte[] array to javascript.
4. I want the javascript to write that byte array as PDF in client machine.

If the above can be done, Please let me know how i can code the 3 and 4th steps.
0
Comment
Question by:salinigayathri
1 Comment
 
LVL 15

Accepted Solution

by:
crisco96 earned 2000 total points
ID: 29122323
JavaScript can't just save a file to a client machine otherwise that would open the door to all kinds of hacking such as writing a virus to a user just for going to a website.

An alternative way to give the user a pdf (but not writing it directly to their computer) is with the code below
//set the conttent type of the file to be downloaded
System.Web.HttpContext.Current.Response.ContentType = "application/pdf";

//add the response headers
System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=\"somepdf.pdf");

//add the contents of the result set to the response stream
System.Web.HttpContext.Current.Response.BinaryWrite(byteArray);

//end the http response
System.Web.HttpContext.Current.Response.End();

Open in new window

0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question