Click here to Skip to main content
13,353,322 members (58,008 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am using C#, as tools.

I am using the following code to transmit and open a file at client side and want to open built-in print dialog box of any application (like word,pdf reader) on the same time while opening the document at client side.

if (fileFormat.ToUpper() == "Excel")
    Response.ContentType = "application/";
else if (fileFormat.ToUpper() == "PDF")
    Response.ContentType = "application/pdf";

Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", fi.Name));
Response.AddHeader("Content-Length", fi.Length.ToString());
Posted 11-Dec-12 3:39am
Updated 12-Dec-12 20:27pm
Adam R Harris 11-Dec-12 11:22am
You cant, and shouldn't be able to. Your code isn't opening the file you are sending down the pipe, the user is when they click Open or Save. You are simply sending a file down to the browser, you have no control over what actions the user takes with that file. I for one would not want random websites to be able to download a file and execute it on my machine it's just asking for trouble. If you really want the user to get the print dialog after downloading your file you might want to take a look at building an ActiveX shim, no one installs ActiveX controls anymore but you can try, then open the file and pass in the print verb once the file has been downloaded.
Akbar Ali Hussain 11-Dec-12 12:22pm
You can add VBA macros to show Print dialog when open Excel and Word documents
Adam R Harris 11-Dec-12 13:13pm
Good point, i didn't think of that. If he simply added a Macro that called print when the document opened that just might accomplish what he is looking for. Should have made this a solution so i could have up voted it.
Akbar Ali Hussain 12-Dec-12 13:01pm
Thanks... I added as solution too.. :)
ahsanriaz1K 12-Dec-12 1:49am
Thanks for replying.. I will try VBA macros.
Sergey Alexandrovich Kryukov 11-Dec-12 14:31pm
Why? Enforcing users is not nice. The user knows better when to print.
ahsanriaz1K 12-Dec-12 1:49am
I want it when user clicks on print button.
Ever thought what the user would want? Above, you said "on the same time while opening the document at client side". This is not the same... and, again, why?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Add a VBA macro to show Print dialog when open Excel and Word documents which are provided for download
ahsanriaz1K 13-Dec-12 1:26am
It is a possible solution. I will try it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100