none
Creating a web browser in C# without web browser control

    Question

  • Hey guyz, I'm takin a beginner's class in C# but the projects are ridiculously hard, like the one I've been given now. It's to create a web browser WITHOUT using the inbuilt browser control in Visual Studio that implements some requirements such as:
    sending HTTP request messages for URLs typed by user.
    Receiving HTTP response messages & display contents of the messages on the interface.
    allowing user to create & edit HomePage URL, & should be loaded on startup.
    allowing user to create a list of Favourite webpages.
    Maintaining History.
    Create tabs on the browser.
    Moreover, the professor has said use the Apache web server for backend and use multithreading in the development of the web browser to separate the browser-server communication from the GUI support.
    I've spent 2-3 days surfing the web for help but everywhere I see ppl using the inbuilt control, which is not exactly helpful plus my limited knowledge on C# & lack of teacher support, so I would definitely appreciate if I could get some ideas on how to go about this project. If someone can point me in the right direction to creating some aspects of this project & providing code/links, that would be great as I'm totally stumped.
    Thanks in advance,
    Vick
    Friday, November 06, 2009 4:48 PM

Answers

  • Store the homepage as a setting. (How to: Add or Remove Application Settings ). Create a button to set it or do it on closing. Don't forget to save.

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        // set property
        Properties.Settings.Default.homepage = urlTxtBox.Text;

        // saving
        Properties.Settings.Default.Save();
    }
    • Marked as answer by demonfox33 Friday, November 13, 2009 2:56 PM
    Saturday, November 07, 2009 10:33 PM
  • Reload would be as simple as doing myHttpWebResponse.GetResponseStream() again. Stop, seems like myHttpWebResponse.Abort(). Back and forward would be somewhat tricky. You'd either have a list of urls and add to the end of the list as you "navigate" to another url or have a dictionary of "url" keys and "buffer" values (both can be of type string since you're working with textbox). Implement a control variable that would increment or decrement as you go back and forward.
    • Marked as answer by demonfox33 Friday, November 13, 2009 2:56 PM
    Sunday, November 08, 2009 8:58 PM

All replies


  • Not exactly what I would call a beginner's project.

    Web Browsers can get pretty complicated with all of the formatting and pictures, etc.
    But you can display web pages without the images, just plain text and links.


    Displaying Web-Style Links with the Windows Forms RichTextBox Control


    Good Luck.  Post back with *specific* questions.

    Rudy   =8^D
    Mark the best replies as answers. "Fooling computers since 1971."
    Friday, November 06, 2009 8:17 PM
  • Tell me about it.. I'm at a total loss on how to go about it. I've created the design for the web browser but the code is what is baffling me. For the design, I created a toolstrip with buttons for back, forward, refresh webpage, stop, homepage, Go button & a textbox to type the URL. Beneath the toolstrip, I inserted a textbox to show the webpage content. On the click of the Go button, I inserted the following code to load the webpage requested by user (eg: http://www.google.com):
    // Prepare web request...
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(this.urlTxtBox.Text);
    
                
                
                // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
                HttpWebResponse myHttpWebResponse= (HttpWebResponse)myRequest.GetResponse();
    
                // Display the contents of the page to the console.
                Stream streamResponse=myHttpWebResponse.GetResponseStream();
    
                // Get stream object
                StreamReader streamRead = new StreamReader(streamResponse);
    
                Char[] readBuffer = new Char[256];
                // Read from buffer
                int count = streamRead.Read( readBuffer, 0, 256 );
                while (count > 0)
                    {
                    // get string
                    String resultData = new String( readBuffer, 0, count);
    
                    // Write the data
                    textBox1.Text +=  ( resultData );
                     
                    // Read from buffer
                    count = streamRead.Read( readBuffer, 0, 256);
                    }
    
                // Release the response object resources.
    
                streamRead.Close();
                streamResponse.Close();
    
                // Close response
                myHttpWebResponse.Close();
    Luckily this works & it returns the webpage requested. But what do I have to do to save google.com as the homepage and for the option of allowing the user the choose a different URL for homepage?
    Saturday, November 07, 2009 2:15 PM
  • Store the homepage as a setting. (How to: Add or Remove Application Settings ). Create a button to set it or do it on closing. Don't forget to save.

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        // set property
        Properties.Settings.Default.homepage = urlTxtBox.Text;

        // saving
        Properties.Settings.Default.Save();
    }
    • Marked as answer by demonfox33 Friday, November 13, 2009 2:56 PM
    Saturday, November 07, 2009 10:33 PM
  • Thanx a lot levelupl0x, that really helped:) Appreciate it! Would you or anyone else happen to know how to code the 4 web browser buttons for back, forward, reload and stop??
    Also, how can I create new web window and ensure that a user can request more than one web page in different windows simultaneously or in tabs? Any ideas??

    Thanx in advance,
    Vick
    Sunday, November 08, 2009 8:07 AM
  • Reload would be as simple as doing myHttpWebResponse.GetResponseStream() again. Stop, seems like myHttpWebResponse.Abort(). Back and forward would be somewhat tricky. You'd either have a list of urls and add to the end of the list as you "navigate" to another url or have a dictionary of "url" keys and "buffer" values (both can be of type string since you're working with textbox). Implement a control variable that would increment or decrement as you go back and forward.
    • Marked as answer by demonfox33 Friday, November 13, 2009 2:56 PM
    Sunday, November 08, 2009 8:58 PM
  • For the stop, shouldn't it be the request & not the httpwebresponse? Anywayz, what about the part where I have to ensure whether a user can request more than 1 web page in different windows simultaneously? My idea is to create multiple tabs on the browser & have the word loading on the title bar before the page is loaded, to prove the above requirement. Any ideas on that??
    Monday, November 09, 2009 11:00 AM
  • For the back and forward, I anyway have to create a History where a list of the previously typed URL's have to be maintained and the user should be able to navigate previous pages requested by clicking on the links in this list. I'm assuming this can be done through filestream, where i'll stream the url links to an external textfile and then import them again as links when the user clicks on any link. The back and forward buttons can then be created simply from the history, isn't that correct? But how do I create a history list and get the link for restreaming a previously typed URL when the user clicks on a link?
    TextWriter tw = new StreamWriter("browser.txt");
                tw.WriteLine(this.urlTxtBox.Text);
                tw.Close();
    Tuesday, November 10, 2009 8:20 AM
  • id use a List<> or Dictionary<> for storing the previously used urls for back, and forward buttons. Definately NEVER write things to a file like that.
    Monday, January 11, 2010 5:03 AM
  • Hey guyz, I'm takin a beginner's class in C# but the projects are ridiculously hard, like the one I've been given now. It's to create a web browser WITHOUT using the inbuilt browser control in Visual Studio that implements some requirements such as:
    sending HTTP request messages for URLs typed by user.
    Receiving HTTP response messages & display contents of the messages on the interface.
    allowing user to create & edit HomePage URL, & should be loaded on startup.
    allowing user to create a list of Favourite webpages.
    Maintaining History.
    Create tabs on the browser.
    Moreover, the professor has said use the Apache web server for backend and use multithreading in the development of the web browser to separate the browser-server communication from the GUI support.
    I've spent 2-3 days surfing the web for help but everywhere I see ppl using the inbuilt control, which is not exactly helpful plus my limited knowledge on C# & lack of teacher support, so I would definitely appreciate if I could get some ideas on how to go about this project. If someone can point me in the right direction to creating some aspects of this project & providing code/links, that would be great as I'm totally stumped.
    Thanks in advance,
    Vick

    Hi, Vick.

    My name is Janet. You wrote this question 3 years ago. And now I (can you imagine) have the same, absolutely the same (word by word) task in my assignment. In addition, I'm a beginner in c# too! I don't know from which side I should approach to this project. You've been in the same situation 3 years ago. I think you can understand me. The situation would be ridiculous if it was not so sad. I'd be grateful for any help. Where did you find sources, what books did you use, if used. Please, at least can you answer these questions. Please, Vick, if you receive this message, do not ignore. Coz I'm in despair. It's too little time remained.

    Thanks in advance. I can leave my email: comiq@yandex.ru


    Monday, October 22, 2012 1:43 AM