Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9010367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:26:14+00:00 2026-06-16T02:26:14+00:00

I am using C#, asp.net as tools. I am using the following code to

  • 0

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 (lfileFormat.ToUpper() == "Excel")
                {
                    Response.ContentType = "application/vnd.ms-excel";
                }
                else if (lfileFormat.ToUpper() == "PDF")
                {
                    Response.ContentType = "application/pdf";
                }
                else if (lfileFormat.ToUpper() == "HTML")
                {
                    Response.ContentType = "text/HTML";
                }


                Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", fi.Name));
                Response.AddHeader("Content-Length", fi.Length.ToString());
                Response.TransmitFile(fi.FullName);
                Response.End();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T02:26:15+00:00Added an answer on June 16, 2026 at 2:26 am

    There is no straight-forward way to do that. You are generating your file server-side, and sending it to the client. You can’t control what is happening on the client’s computer (as HollyStyles mentions, imagine the mess).

    Your best bet is to include a macro inside the Excel/Word file so that it will show the print dialog on file open. Easiest way to do without messing with VBE (Visual Basic Extensibility, which allows to dynamically manipulate code modules of Office documents) is to create a template that includes the functionnality, and use that template to generate your documents.

    For exemple, in an Excel worbook open event handler, you can have :

    Private Sub Workbook_Open()
    
        Application.Dialogs(xlDialogPrint).Show
    
    End Sub
    

    But that has other implications (make sure your documents are signed, or that the users allow execution of macros, …). Not to mention that the Print dialog will show up everytime the user the file, which can be… irritating.

    Additionnally, that won’t solve the problem for non-office files. You could use Window.Print in JS to handle those case.

    But all in all, it’s going to be messy 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which storage method should I use when using ASP.NET Charting Tools? I'm currently using
I have the following acceptance criteria for creating a pdf file from my asp.net
I am following the tutorial here: http://www.aspfree.com/c/a/XML/Applying-XSLT-to-XML-Using-ASP.NET/2/ The tutorial shows how one converts xml
I am using the CSD tool to create custom configuration sections in my asp.net
Using ASP.net and c# using visual studio 2010 Hi all, I hope some one
Using ASP.Net MVC on my Site.Master I have: <head runat=server> <title><asp:ContentPlaceHolder ID=TitleContent runat=server />
Using ASP.NET 3.5 and jQuery UI. When a user clicks the Search button, a
Using asp.net 3.5 Gridview control, visual studio 2008. I have played with all the
Using ASP.NET MVC when trying to get the information stored on my Session[objectName] from
Using ASP.NET MVC 2.0, I have an actionlink that is used for comments on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.