Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How I can open HTML page with html source code in Winapplication,without Create a file?

How I can open HTML page with html source code in Winapplication,without Create a file?

Scheduled Pinned Locked Moved C#
csharphtmldatabasehelpquestion
15 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Farrukh_5

    well then you need to use memory stream as the source for the browser to read the html contents, but im not sure about this that either browser will read from this memory stream or not what else can be done is you embed the browser control (if IE) in your application and then try to send html text to that browser control programmically --------------------------- http://www.idlsol.com

    N Offline
    N Offline
    Nafiseh Salmani
    wrote on last edited by
    #5

    memory stream!! what do u mean by memory stream? :confused:

    F 1 Reply Last reply
    0
    • N Nafiseh Salmani

      memory stream!! what do u mean by memory stream? :confused:

      F Offline
      F Offline
      Farrukh_5
      wrote on last edited by
      #6

      well i never used streams but i read about them while i was doing file handling in dot net, search on google you might get something http://www.google.com/search?hl=en&q=creating+memory+stream+in+C%23&btnG=Search --------------------------- http://www.idlsol.com

      N 1 Reply Last reply
      0
      • F Farrukh_5

        well i never used streams but i read about them while i was doing file handling in dot net, search on google you might get something http://www.google.com/search?hl=en&q=creating+memory+stream+in+C%23&btnG=Search --------------------------- http://www.idlsol.com

        N Offline
        N Offline
        Nafiseh Salmani
        wrote on last edited by
        #7

        I read it, thanks, but there is a problem for using memory stream as a solution : how i can bind a memory stream file to a web browser??!!! :confused:

        1 Reply Last reply
        0
        • N Nafiseh Salmani

          hi I read html source code from a DB(Access), I want to load this page with click on a button , without create a file .:confused: (in windows application C#.net) thanks for your help Salmani

          E Offline
          E Offline
          emran834
          wrote on last edited by
          #8

          If you want to load HTML file in a webbrowser control, Its the straight forward way to set the property value of DocumentText of the Webbrowser with the HTML string. Example, If your Webbrowser control has instance name, webBrowserControlMyBrowser then string htmlString = " Hello World "; webBrowserControlMyBrowser.DocumentText = htmlString; In this way, You dont need to create a file, save and delete etc, moreover, you dont even need to wait for couple of seconds to load. Its the DIRECT way. Emran

          N 1 Reply Last reply
          0
          • E emran834

            If you want to load HTML file in a webbrowser control, Its the straight forward way to set the property value of DocumentText of the Webbrowser with the HTML string. Example, If your Webbrowser control has instance name, webBrowserControlMyBrowser then string htmlString = " Hello World "; webBrowserControlMyBrowser.DocumentText = htmlString; In this way, You dont need to create a file, save and delete etc, moreover, you dont even need to wait for couple of seconds to load. Its the DIRECT way. Emran

            N Offline
            N Offline
            Nafiseh Salmani
            wrote on last edited by
            #9

            Thanks. but im working with VisualStudio.net 2003, and this property "DocumentText" is not valid for web browser control!!! :confused: Salmani

            F 1 Reply Last reply
            0
            • N Nafiseh Salmani

              Thanks. but im working with VisualStudio.net 2003, and this property "DocumentText" is not valid for web browser control!!! :confused: Salmani

              F Offline
              F Offline
              Farrukh_5
              wrote on last edited by
              #10

              there might be some other property man, try to find it :zzz: --------------------------- http://www.idlsol.com

              N 1 Reply Last reply
              0
              • F Farrukh_5

                there might be some other property man, try to find it :zzz: --------------------------- http://www.idlsol.com

                N Offline
                N Offline
                Nafiseh Salmani
                wrote on last edited by
                #11

                I tried all of them before, i searched all of sites and MSDN library , but i couldnt find it ! :doh:

                1 Reply Last reply
                0
                • N Nafiseh Salmani

                  hi I read html source code from a DB(Access), I want to load this page with click on a button , without create a file .:confused: (in windows application C#.net) thanks for your help Salmani

                  A Offline
                  A Offline
                  ahmad2x4
                  wrote on last edited by
                  #12

                  Hi I please follow thease steps, I think it'll help you to solve the problem first of all create a Windows application drop a WebBrowser on form1 (leave the name webBrowser1) change the Url property to about:blank drop a button double click on the button1 and paste this code for event handler

                          private void button1_Click(object sender, EventArgs e)
                          {
                              System.IO.MemoryStream st = new System.IO.MemoryStream ();
                              string sampleHtml = "Hello world! ";
                              UTF8Encoding uniEncoding = new UTF8Encoding();
                  
                              // Create the data to write to the stream.
                              byte[] firstString = uniEncoding.GetBytes(
                                  sampleHtml);
                  
                              webBrowser1.DocumentStream = st;
                              st.Write(firstString, 0, firstString.Length);
                              st.Flush();
                              st.Position = 0;
                              webBrowser1.DocumentStream = st;
                          }
                  

                  Ahmadreza Atighechi

                  1 Reply Last reply
                  0
                  • N Nafiseh Salmani

                    hi I read html source code from a DB(Access), I want to load this page with click on a button , without create a file .:confused: (in windows application C#.net) thanks for your help Salmani

                    A Offline
                    A Offline
                    ahmad2x4
                    wrote on last edited by
                    #13

                    Hi Please do the following steps, I think it'll help you Create a new windows application Drop a WebBrowser Control to Form1 (leave the webBrowser1 as name) change property Dock to none change the property Url to about:blank drop a button to form1 (leave the button1 as name) bouble click on the button1 and paste following code as event handler

                            private void button1_Click(object sender, EventArgs e)
                            {
                                System.IO.MemoryStream st = new System.IO.MemoryStream ();
                                string sampleHtml = "Hello world! ";
                                UTF8Encoding uniEncoding = new UTF8Encoding();
                    
                                // Create the data to write to the stream.
                                byte[] firstString = uniEncoding.GetBytes(
                                    sampleHtml);
                    
                                webBrowser1.DocumentStream = st;
                                st.Write(firstString, 0, firstString.Length);
                                st.Flush();
                                st.Position = 0;
                                webBrowser1.DocumentStream = st;
                            }
                    

                    Ahmadreza Atighechi ..:--::..

                    1 Reply Last reply
                    0
                    • N Nafiseh Salmani

                      hi I read html source code from a DB(Access), I want to load this page with click on a button , without create a file .:confused: (in windows application C#.net) thanks for your help Salmani

                      N Offline
                      N Offline
                      Nafiseh Salmani
                      wrote on last edited by
                      #14

                      I finally find out!!:) object empty = System.Reflection.Missing.Value; axWebBrowser1.Navigate("about:blank", ref empty, ref empty, ref empty, ref empty); mshtml.IHTMLDocument2 doc = axWebBrowser1.Document as mshtml.IHTMLDocument2; doc.clear(); doc.writeln("This is my text..."); doc.close(); doc = axWebBrowser1.Document as mshtml.IHTMLDocument2; doc.execCommand("Print", true, 0);

                      N 1 Reply Last reply
                      0
                      • N Nafiseh Salmani

                        I finally find out!!:) object empty = System.Reflection.Missing.Value; axWebBrowser1.Navigate("about:blank", ref empty, ref empty, ref empty, ref empty); mshtml.IHTMLDocument2 doc = axWebBrowser1.Document as mshtml.IHTMLDocument2; doc.clear(); doc.writeln("This is my text..."); doc.close(); doc = axWebBrowser1.Document as mshtml.IHTMLDocument2; doc.execCommand("Print", true, 0);

                        N Offline
                        N Offline
                        Nafiseh Salmani
                        wrote on last edited by
                        #15

                        :doh: there are another problem !!! in this method , how can i show images that there were in html source ?? i see : about blank ../../images/sx.jpeg with right click on picture in web browser .so what can i do??

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups