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 8608635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:39:51+00:00 2026-06-12T03:39:51+00:00

Well, for example I have some simple console application. My purpose is to generate

  • 0

Well, for example I have some simple console application. My purpose is to generate some report and represent it to the user in some external application such as notepad or a web browser.

class Program
    {
        [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("User32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

        static void Main()
        {
            OpenNotepadAndInputTextInIt("Message in notepad");
            OpenHtmlFileInBrowser(@"c:\temp\test.html");
        }

        private static string GetDefaultBrowserPath()
        {
            string key = @"HTTP\shell\open\command";
            using(RegistryKey registrykey = Registry.ClassesRoot.OpenSubKey(key, false))
            {
                return ((string)registrykey.GetValue(null, null)).Split('"')[1];
            }
        }

        private static void OpenHtmlFileInBrowser(string localHtmlFilePathOnMyPc)
        {
            Process browser = Process.Start(new ProcessStartInfo(GetDefaultBrowserPath(), string.Format("file:///{0}", localHtmlFilePathOnMyPc)));
            browser.WaitForInputIdle();

        }

        private static void OpenNotepadAndInputTextInIt(string textToInputInNotepad)
        {
            Process notepad = Process.Start(new ProcessStartInfo("notepad.exe"));
            notepad.WaitForInputIdle();
            if(notepad != null)
            {
                IntPtr child = FindWindowEx(notepad.MainWindowHandle, new IntPtr(0), "Edit", null);
                SendMessage(child, 0x000C, 0, textToInputInNotepad);
            }
        }
    }

This solution works fine, But as you can see I have two methods; GetDefaultBrowserPath() and GetDefaultBrowserPath(string localHtmlFilePathInMyPc). The first one passes message string directly to notepad window, but the second one needs to create a file, some html page, and than pass this html file as parameter for the web browser. This is kind of a slow solution. I want to generate an html string report and pass it directly to a web browser without creating intermediate html files.

  • 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-12T03:39:53+00:00Added an answer on June 12, 2026 at 3:39 am

    If you want to open an external browser window (rather than integrating one into your application) in the system’s default browser application I think the only way is going via a data URI:

    data:text/html,<html><title>Hello</title><p>This%20is%20a%20test
    

    Pass this as the URI into the browser. However, I wouldn’t really advise doing this. It’s unexpected for the user and there isn’t really a disadvantage in generating a temporary file to be displayed, is there? In addition, you might start hitting restrictions on the URI length pretty quickly.

    Incidentally, your current way of opening a file in the browser is way more complicated than required. Shell execution does the right thing on its own, no need to retrieve the browser’s path from the registry manually:

    Process.Start("file:///the/path/here")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spatial search working well with SOLR 3.2 Example : ?q=*&fq={!geofilt pt=48.86761919303129,2.3527903735351856 sfield=coordinates
I have seen the example here . All well and good and I understand
I have a websites www.example.com which is a druapal 6 site. Works well, never
I have some simple scripts that allow me to change where certain versions of
I have some Zend Framework apps running and it's time to add user access
I have a need to do some fairly simple (at least on the surface)
Im currently developing a MVC application Framework and I have come for some advise
I have a simple photo taking application that has the following design: [Consider the
Well, I got my HexString (PacketS) for example 70340A0100000000000000 I want to split every
I'm just starting with The Well-Grounded Rubyist, and they gave the following example: print

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.