View > Source

G

Guest

hey everybody,

I have written a great browser but it is missing a feature (quite a lot
actually, but forget about them for now). that feature just so happens to be
the View > Source function. for those of you who don't what i mean, it is
when you click a button in the view menu that says Page source (in Netscape)
and source (in Internet Explorer). if you click it, notepad opens. in that
window is the html for the page.

anyway, does anyone know how to show the source?
 
G

Guest

The easiest way for you to do it would be to make sure you’ve got a copy of
the source saved to some temporary location and launch a copy of notepad via
the Process class with either the /A or /W argument followed by the filename
of this temp file.

If you wanted to stay completely within your code, a new form with a large,
multi-line textbox too would do the job, however for my money I would
probably go with notepad just because of it’s simplicity.

Just for note, with regards to the above arguments, /A opens the file as an
ANSI file while /w opens it as Unicode.

Brendan
 
G

Guest

hi,

thanks brendan. i want to do it with the new form because it would seem more
simple and it would take up less storage space on your HDD. would you know
how to do that?
 
G

Guest

To do it all within your C# app I would do it as follows:

1. Create a new Windows Form.
2. Add a textbox to the form and name it sourceTextBox
3. Set Multiline to True and Dock to fill on sourceTextBox
4. Add the following property to the code of the Form:
public string Source
{
set
{
sourceTextBox.Text = value;
}
}

5. When in your code you wish to view the source, simply create a new
instance of your newly created source viewing form, set the Source property
on it equal to the string containing the source, and call the Show() or
ShowDialog() method on it to display it.

Simple enough?

Brendan
 
G

Guest

hi,

i get a message saying: 'Source': member names cannot be the same as their
enclosing type

what does it mean?

by the way, here is the line with the error:

public string Source() // <<Error here
{
set;
{
sourceTextBox.Text = value;
}
}
 
D

Dan Bass

remove the parenthesis... should just be "public string Source" as it's
a property, not a method.
 
G

Guest

hi,

thanks but now i get an error on one of the curly brackets instead of the
Source:

public string Source
{
set;
{ // <<error here. It says: a get or set accessor expected
sourceTextBox.Text = value;
}
}

cheers,
 
S

Steve Walker

Alvo said:
hey everybody,

I have written a great browser but it is missing a feature (quite a lot
actually, but forget about them for now). that feature just so happens to be
the View > Source function. for those of you who don't what i mean, it is
when you click a button in the view menu that says Page source (in Netscape)
and source (in Internet Explorer). if you click it, notepad opens. in that
window is the html for the page.

What do you mean when you say you've "written" a browser; do you mean
that you've written one from the ground up (in which case only you know
how to get to the raw html) or that you've embedded the IE browser in
your application?

If it's the latter, then something like:

mshtml.HTMLDocumentClass doc =
(mshtml.HTMLDocumentClass)this.axWebBrowser1.Document;
MessageBox.Show(doc.documentElement.innerHTML);

should do what you want.
 
B

Bill Butler

Alvo von Cossel I said:
hi,

thanks but now i get an error on one of the curly brackets instead of the
Source:

public string Source
{
set;
{ // <<error here. It says: a get or set accessor expected
<snip>

Lose the semicolon after the set
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top