Click here to Skip to main content
15,894,896 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.

C#
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
Updated 12-Dec-12 19:27pm
v2
Comments
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.

1 solution

Add a VBA macro to show Print dialog when open Excel and Word documents which are provided for download
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900