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

  • Home
  • SEARCH
  • 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 8990437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:30:01+00:00 2026-06-15T22:30:01+00:00

I have this peculiar problem while wanting to print a html-report. The file itself

  • 0

I have this peculiar problem while wanting to print a html-report. The file itself is a normal local html file, located on my hard drive.

To do this, I have tried the following:

    public static void PrintReport(string path)
    {
        WebBrowser wb = new WebBrowser();
        wb.Navigate(path);
        wb.ShowPrintDialog()
    }

And I have this form with a button with the click event:

    private void button1_Click(object sender, EventArgs e)
    {
        string path = @"D:\MyReport.html";
        PrintReport(path);
    }

This does absolutely nothing. Which is kind of strange… but things get stranger…

When editing the print function to do the following:

    public static void PrintReport(string path)
    {
        WebBrowser wb = new WebBrowser();
        wb.Navigate(path);
        MessageBox.Show("TEST");
        wb.ShowPrintDialog()
    }

It works. Yes, only adding a MessageBox. The MessageBox is showing and after it comes the print dialog. I have also tried with Thread.Sleep(1000) instead, which doesn’t work. Can anyone explain to me what’s going on here? Why would a messagebox make any difference?

Can it be some kind of permission problem? I’ve reproduced this on both Windows 7 and 8, same thing. I made this small application with only the above code to isolate the problem. I am quite sure it works on windows XP though, since an older version of the application I’m working on runs on it. When trying to do this directly with the mshtml-dll instead I also get problems.

Any input or clarification is greatly appreciated!

  • 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-15T22:30:02+00:00Added an answer on June 15, 2026 at 10:30 pm

    The problem is that the browser is not ready to print yet. You will want to add an event handler WebBrowserDocumentCompletedEventHandler to the WebBrowser Object. Sample code below.

    public static void PrintReport(string path)
    {
        WebBrowser wb = new WebBrowser();
        wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser_DocumentCompleted);
        wb.Navigate(path);
    }
    
    public static void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        WebBrowser wb = (WebBrowser)sender;
        if (wb.ReadyState.Equals(WebBrowserReadyState.Complete))
            wb.ShowPrintDialog();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a work around for this problem, but I've been noticing some peculiar
have a peculiar problem with hibernate. I have a hibernate function like this. @SuppressWarnings(unchecked)
I have a very peculiar problem. I understand that while in the foreground the
I'm facing this peculiar problem in my silverlight app. I have a Canvas that
I have a very peculiar problem and my last resort was asking this on
I have run into a peculiar problem. Some HTML text on my page becomes
I have a peculiar problem here. I want to extract some generic types, which
I have a peculiar problem here and I can't by my life figure out
I have a peculiar problem when calling a web service that expects the message
This perhaps is a peculiar problem and I do need a second eye. I

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.