Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET Client
Hi,
I am using C#, asp.net 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/vnd.ms-excel";
                }
                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());
                Response.TransmitFile(fi.FullName);
                Response.End();
Posted 11-Dec-12 3:39am
Edited 12-Dec-12 20:27pm
v2
Comments
Adam R Harris at 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 at 11-Dec-12 12:22pm
   
You can add VBA macros to show Print dialog when open Excel and Word documents
Adam R Harris at 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 at 12-Dec-12 13:01pm
   
Thanks... I added as solution too.. :)
ahsanriaz1K at 12-Dec-12 1:49am
   
Thanks for replying.. I will try VBA macros.
Sergey Alexandrovich Kryukov at 11-Dec-12 14:31pm
   
Why? Enforcing users is not nice. The user knows better when to print.
--SA
ahsanriaz1K at 12-Dec-12 1:49am
   
I want it when user clicks on print button.
Sergey Alexandrovich Kryukov at 12-Dec-12 1:55am
   
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?
—SA

1 solution

Rate this: bad
good
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
  Permalink  
Comments
ahsanriaz1K at 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
0 Afzaal Ahmad Zeeshan 256
1 OriginalGriff 251
2 BillWoodruff 240
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2014
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