Load a page from an html string

Asked

Viewed 958 times

0

I am with the following doubt that, I believe that although it is beast, it is giving me a beautiful job.

Next, I have a variable like string and I need to perform a method that will receive this code and display the page in a new tab. I was using the library SelectPdf to convert this string in a PDF but when using with Azure it does not work so lost here. Someone can help me?

2 answers

0

You only need to open a web page from a link in your application?

If that’s it, try:

System.Diagnostics.Process.Start("http://seu_site_aqui");

To open in new tab, you can use the attribute target=_blank in a simple link, for example:

<a href="http://seu_site_aqui" target="_blank" >Clique aqui</a>
  • is not a page, the page(html code) is inside a variable of type string and it is the one that I want to click on a page. In other words I want to render my variable on a new page

  • @user24203 I’m glad you didn’t like this gambiarra :)

  • you want to simulate the behavior of an HTML <iframe> then? Display the contents of one html page within another?

  • Yes that’s right, but not necessarily because I will open in a new window not in the current page

0


Let’s see, you could create an HTML file based on its string using the IO class, which would take it and turn it into a file, and write it in the same place where your application is. Then just open it using the:

System.Diagnostics.Process.Start("http://seu_site_here");

That’s it. I’ve done it many times.

Let’s see, I realized you don’t quite understand what I mean, so I’ll demonstrate with this pseudocode:

string suaString = "<!DOCTYPE html><html>...</html>";
StreamWriter escritor = new StreamWriter(@"...\paginaQueDesejo.html");
escritor.WriteLine(suaString);
escritor.Close();

// Pronto, sua pagina foi criada e está pronta para ser exibida, agora é só exibí-la.
System.Diagnostics.Process.Start(@"...\paginaQueDesejo.html");

Just this, I don’t know if this will solve your problem, but in most cases this is a simple and efficient solution.

  • It is not a page, the page(html code) is inside a variable of type string and it is the one that I want to click on a page. In other words I want to render my variable on a new page

Browser other questions tagged

You are not signed in. Login or sign up in order to post.