Posts 1 - 10 of 11
First | Prev. | 1 2 | Next | Last
|
|
Busy Cougar
Posts: 5
Joined: 2011-05-16
|
Hi
I want to do the following and wanted to know if it was possible using Add-In express for IE:
1. Create a toolbar button for Internet Explorer
2. When user visits a web - page and clicks the button, custom .NET code is executed that can grab the code behind of the page and parse out a specific section of the code behind text
3. Save the parsed out text to a file or a database
Is this possible via .NET code on the click event of an IE Command via this product? |
|
Posted 16 May, 2011 21:13:10
|
|
Top
|
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Busy,
The answer is 'yes' for all questions. |
|
Posted 17 May, 2011 05:41:15
|
|
Top
|
|
Busy Cougar
Posts: 5
Joined: 2011-05-16
|
Hi
Would it be possible for you to send me a code snippet in C# to grab the code behind in the click event of the Add-In Express IE command.
Thanks |
|
Posted 17 May, 2011 06:30:08
|
|
Top
|
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Busy,
Here is the code of the OnClick event handler of a context menu item:
private void adxieContextMenuCommandItem1_OnClick(object sender, object eventObject)
{
if (eventObject is mshtml.IHTMLSelectionObject)
{
mshtml.IHTMLSelectionObject selection =
eventObject as mshtml.IHTMLSelectionObject;
mshtml.IHTMLTxtRange textRange = selection.createRange() as mshtml.IHTMLTxtRange;
if (textRange != null)
{
if (!String.IsNullOrEmpty(textRange.text))
MessageBox.Show(textRange.text);
else if (!String.IsNullOrEmpty(textRange.htmlText))
MessageBox.Show(textRange.htmlText);
}
}
} |
|
Posted 17 May, 2011 06:49:45
|
|
Top
|
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Busy,
In the latest version of the product (v7.0.4101) the code above is a bit different:
private void adxieContextMenuCommandItem1_OnClickEx(object sender, ADXIEMenuItemClickEventArgs e)
{
if (e.Selection != null)
{
mshtml.IHTMLSelectionObject selection =
e.Selection as mshtml.IHTMLSelectionObject;
mshtml.IHTMLTxtRange textRange = selection.createRange() as mshtml.IHTMLTxtRange;
if (textRange != null)
{
if (!String.IsNullOrEmpty(textRange.text))
MessageBox.Show(textRange.text);
else if (!String.IsNullOrEmpty(textRange.htmlText))
MessageBox.Show(textRange.htmlText);
}
}
} |
|
Posted 18 May, 2011 05:37:03
|
|
Top
|
|
Busy Cougar
Posts: 5
Joined: 2011-05-16
|
thanks for this.
1. Would selection.createRange() give me the selected text or the entire code behind of the loaded page with html tags etc. On IE for example, one can click on "view source" and view the entire html source. That is the information that I want to extract via code.
2. Similarly, how can I get hold of the selected \ highlighted text from the contents of the loaded page. Wouldn't selection.createRange() be used for this.
3. Another question is that if I plan to create an IE Bar or an IEToolbar, could the above logic be used from a button on the toolbar?
Thanks |
|
Posted 19 May, 2011 07:00:56
|
|
Top
|
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Busy,
1. The 'text' property returns just a text.
2. If a web page contains any selected text/content, you will get it via the IHTMLSelectionObject interface.
3. Yes, you can use the code above from a BHO, toolbar or explorer bar. |
|
Posted 19 May, 2011 08:39:00
|
|
Top
|
|
Busy Cougar
Posts: 5
Joined: 2011-05-16
|
Thanks Sergey for the quick replies. You guys are awesome.
From your replies above it seems to me that the code above will give me back the text. I want to retrieve the HTML Code programmatically with the HTML tags etc, similar to what you can see by right clicking on IE and clicking on "View Source" |
|
Posted 19 May, 2011 09:07:34
|
|
Top
|
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
To get the HTML source you can use the 'htmlText' property as shown in the example. |
|
Posted 19 May, 2011 09:24:11
|
|
Top
|
|
Busy Cougar
Posts: 5
Joined: 2011-05-16
|
Got it.
Can this HTMLText be written and saved to a txt, doc file on the file system?
Do add-ons have nay sort of restrictions to save douments? |
|
Posted 19 May, 2011 15:48:53
|
|
Top
|
|
Posts 1 - 10 of 11
First | Prev. | 1 2 | Next | Last
|