html <pre></pre> page layout blocks links - c#

I am taking a document into an html page to show the user with .Net libraries' help. I am using LoadHtml method under HtmlAgilityPack. But when i use that method to fill the html, it does not show the tab(ascii=09) characters right. So i use it like:
doc.LoadHtml("<pre>" + pContent + "</pre>");
But when i do that then i can not add any picture links or pictures to the html page. normally before i use "< pre >", the user was able to add links. The code below was running behind.
string text = string.Format(#"<img src='{0}' />", thepicturelink);
My problem is that i want to make my page both could be added links(pictures) and looks proper with tab character. I could not find any solution for that in here, msdn, socialmsdn, codeproject or google. Does anyone have a solution for that problem? Thank for helps. Best regards.

Related

How to open some pages by one HyperLink item?

I have an array of some URL links. And I need to open all theese links by clicking one HyperLink, located in cell of Telerik GridHyperLinkColumn.
Is there any method to do this?
Now I have a code which sets first way to my HyperLink:
HyperLink link = (HyperLink) item["documents"].Controls[0];
if (link.NavigateUrl.Contains(";"))
{
string[] linktext = link.NavigateUrl.Split(';');
link.NavigateUrl = linktext[0];
}
I would probably take a quick look at this SO answer here.
The takeaway is that this is not possible without using JavaScript functions:
Without JavaScript, it's not possible to open two pages by clicking
one link unless both pages are framed on the one page that opens from
clicking the link. With JS it's trivial.
The example is this:
<p><a href="#" onclick="window.open('http://google.com');
window.open('http://yahoo.com');">Click to open Google and Yahoo</a></p>
This would also work: (again see answer here)
Open Two Links With One Click

WebPage Render Position Controller

First question but I really am in a jam.
I have a webpage render which is working perfectly. However, I need to be able to control the initial display position (almost like a href #anchors in HTML) but without any access to the site content.
From as far as i can see i have no access to the scrollBars other than the bool to enable / disable..
Is there anything i can do to even force a scroll down of 20% for example, and then I can create a form to adjust later on.
Any assistance would be HUGELY appreciated although from what I have researched it seems unlikely.
I have the regular windows WebBrowser Render
private System.Windows.Forms.WebBrowser m_webBrowser;
Thanks !
--This is for c# standalone application.. Not WebBased.
Have you tried using jquery?
I personally use the animate method from jquery to scroll to certain elemnts in my webpage.
Example:
$('html, body').animate({scrollTop: $('#the-element-you-want-to-scroll-to).offset().top}, 1000);
PS: For the last parameter you can control the time it will use to scroll to destination, that offering you a nice effect.(in milliseconds)
I managed to resolve it using a strange method..
I basically injected some javascript into the rendered HTML manually.. Then the rest was easy.
i used something like this :
string updatedSource = WebBrowser.DocumentText.Replace("Google", "Foogle");
string extraSource =
"<html><body>Script goes here <br/>" +
"<div><p>BLA BLA BLA</p></div></body></html>";
WebBrowser.DocumentText = extraSource + updatedSource;
WebBrowser.Update();
Maybe it will help someone.

Building a PDF with links from HTML and other PDFs with abcPDF

I've got some code that builds a PDF from an HTML template, then attaches several other PDFs to make one big PDF using abcPDF 7.
All this works fine and dandy -- however, I'd like to make some links in the HTML portion of the PDF to jump down to one of the several attached PDFs.
I tried creating links and anchors using the technique referenced here, by putting the
Link to another page
link in the HTML, then putting the anchor
<div><a name="elementId">A div that's on another page</a></div>
as an added-on paste-over on the top of the first page of the PDF I wanted to jump to.
I can see the text of the anchor just fine, and the link to it is blue, but it doesn't do anything.
As the next attempt, I've created bookmarks that work as well. Can someone point me in the direction to go back and adjust the links in the HTML portion to use them to jump to the bookmarks?
I apologize in advance for a lack of code, and I'm not asking for any code now.. I'd just like a more general way to go about it, like "try something like this." I'm not having much luck finding anything that is close to what I'm trying to do, not even on WebSuperGoo's website.
This method has worked for me in the latest ABCpdf version (9) Add a bookmark to each page in your document:
For i = 1 to pdf.PageCount
pdf.PageNumber = i
pdf.AddBookmark("Page " & i, True)
Next
Then where you want to insert a link you can reference the bookmark - in this case we create a table of contents by looping through each bookmark we've created:
For Each bm As Bookmark In pdf.Bookmark
toc &= "<Font annots='goto:" + bm.Page.PageNumber.ToString() + "'>" & bm.Title & "</Font><br>"
Next
pdf.AddHtml(toc)
The Websupergoo team supplied me with some example code and that's what this is based off of - so thanks to them!

Click an HTML link inside a WebBrowser Control

C# Visual Studio 2010
I am loading a complex html page into a webbrowser control. But, I don't have the ability to modify the webpage. I want to click a link on the page automatically from the windows form. But, the ID appears to be randomly generated each time the page is loaded (so I believe referencing the ID will not work).
This is the content of the a href link:
<a
id="u_lp_id_58547"
href="javascript:void(0)"
class="SGLeftPanelText" onclick="setStoreParams('cases;212', 212); window.leftpanel.onClick('cases_ss_733');return false; ">
My Assigned</a>
Is the anyway to click the link from C#?
Thanks!
UPDATE:
I feel like this is close but it is just not working:
HtmlElementCollection links = helpdeskWebBrowser.Document.Window.Frames["main_pending_events_frame"].Document.GetElementsByTagName("a");
MessageBox.Show(links.Count.ToString());
I have tried plugging in every single frame name and tried both "a" and "A" in the TagName field but just have not had any luck. I can just not find any links; the message box is always 0. What am I missing?
Something like this should work:
HtmlElement link = webBrowser.Document.GetElementByID("u_lp_id_58547")
link.InvokeMember("Click")
EDIT:
Since the IDs are generated randomly, another option may be to identify the links by their InnerText; along these lines.
HtmlElementCollection links = webBrowser.Document.GetElementsByTagName("A");
foreach (HtmlElement link in links)
{
if (link.InnerText.Equals("My Assigned"))
link.InvokeMember("Click");
}
UPDATE:
You can get the links within an IFrame using:
webBrowser.Document.Window.Frames["MyIFrame"].Document.GetElementsByTagName("A");
Perhaps you will have to isolate the link ID value using more of the surrounding HTML context as a "target" and then extract the new random ID.
In the past I have used the "HtmlAgilityPack" to easily parse "screen-scraped" HTML to isolate areas of interest within a page - this library seems to be easy to use and reliable.

c# webbrowser show what you want

i want create small web browser , tiny and fast
but i have problem ,
let me explain :
1 - user enter site : google.com
2 - c# program get google.com
3 - find <td nowrap="" align="center">
4 - in web browser only show that area
i dont know where i must start ,
thanks
Ok, I'm going to try answer your question, but I am deciphering as well.
Create a WebBrowser control on your form. (2.0 is fine for what you need) and .Navigate("http://www.google.com");
Get the source code from the Document. You can do this as follows: string source = _WebBrowser.Document.Body.OuterHtml;
Use string manipulation to get to the area on the page you need. For instance .SubString() functions
Save the text into a file, or stream and load it into the WebBrowser control, or replace the pages Document HTML with just the HTML you are wanting to show.
Okay! Looking at the comment it seems you want to request for a page using c# and show only one part of the page. In your case its that specific <td> . Please correct me if I am wrong.
Other than what Kyle has mentioned. Check out HTML agility Pack. It might be of interest to you.

Categories