How to get string in web browser in windows phone 8? - html

I have a file html, and i want to get string from this file html. I use web browser for read html, but i don't know how to get string in web browser. Can't you help me. Thank all!
WebBrowser web = new WebBrowser();
web.Source = new Uri("Assets/text.html", UriKind.RelativeOrAbsolute);

Try this:
WebBrouser = new WebBrowser();
WebBrouser.Navigate(new Uri("Assets/text.html", UriKind.Relative);
I am assumed that your html file content is in proper format.

Related

Is it possible to embed a HTML into a PDF?

I like to embed a HTML site into a PDF document. Are there any libraries or PDF creator that make that possible?
Update:
I am not looking for ways to convert a HTML to PDF. I actually want to use the HMTL as it is inside the PDF. So I am looking for something like iframe for PDF.
There are a few out there, depends if you need to build using PHP or another language. I have used MPDF before: http://www.mpdf1.com/mpdf/
Yes, its possible using xmlworker5.4.1.jar. The XML worker object allows you to embed html in your document. xmlString object below is your HTML content as HTMLWorker is deprecated so use XMLWorker only.
XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
String currentLine = "";
StringBuffer xmlString = new StringBuffer();
xmlString.append("<html><body>");
String str = htmlPages[i];
xmlString.append(htmlPages[i]);
xmlString.append("</body></html>");
worker.parseXHtml(pdfWriter, pdfDocument, new StringReader(xmlString.toString()));
Inorder to incorporate fonts mentioned in font face tag u need to register fonts using
FontFanctory.redisterDirectory("path of font files");
because itext doesnt scan system for fonts. u need to register it yourself this way

How to display local html data(which is in string variable) in web browser in windows phone 8

In my windows phone 8 application, When I call the web service I'm getting the response. And the response is html code. Now I have stored the html code in string variable. Now I want to show this html code in the web browser. For this I've used the below code.
myWebBrowser.NavigateToString("myHTMLcode")
But the data is not showing in the page. Please tell me how to do the above. I'm looking forward for valuable response.
Thanks.
Create a WebBrowser control in XAML (make sure it has enough height and width set)
<phone:WebBrowser Name="webBrowser" Height=400 Width=300/>
Then I created a web client to fetch some html page
WebClient client = new WebClient();
client.DownloadStringCompleted += client_DownloadStringCompleted;
client.DownloadStringAsync(new Uri("http://www.google.com", UriKind.Absolute));
When the html is downloaded, show it in our webBrowser control
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
webBrowser.NavigateToString(e.Result);
}
Adopt this to your needs.

How can I get special characters with Web Client in WP?

I want to make dynamic message grid in my application's mainpage and I am getting it from my domain's html file. For example;
html
body
----Böşç Hello----
/body
/html
(I did not write <> tags for understanding.)
and I am getting them with my WebClient. But it is not getting this words "ö,ş,ç" correctly.
How can I do it? or have you any other solution?
Thanks.
Have you tried tweaking the encoding?
WebClient client = new WebClient ();
client.Encoding = System.Text.Encoding.UTF8;

Chome downloads aspx page instead of an excel like it does in IE and firefox

I have a webpage that allows users to download excel reports, in Chrome, it just tries to download an aspx page instead of the excel like it successfully does in IE and Firefox.
Is this a known issue and is there a workaround?
I am using this in VB:
db.subRunReader(resultSQL)
dgProperties.DataSource = db.sqlReader
dgProperties.DataBind()
db.subCloseReader()
db.subCloseConnection()
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim tw As New System.IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
dgProperties.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
Response.Redirect(Request.Url.ToString())
Thanks.
Not sure about your specific situation, but in general whenever you want a file downloaded, it is a good idea to add a Content-Disposition header. In ASP.NET MVC it would be done like this:
Response.Headers["Content-Disposition"] =
"attachment;filename=yourfile.xls";
I expect in ASP.NET 2.0 it would be something similar. This tells the browser that it needs to download the file.

HTML inside webView

I am posting some data to a server using DefaultHttpClient class and in the response stream I am getting a HTML file. I save the stream as a string and pass it onto another activity which contains a WebView to render this HTML on the screen:
response = httpClient.execute(get);
InputStream is = response.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is,"utf-8"));
StringBuffer sb = new StringBuffer();
String line;
while((line=br.readLine())!=null){
sb.append(line);
sb.append("\n");
}
is.close();
Intent intent = new Intent(this,Trial.class);
intent.putExtra("trial",sb.toString());
startActivity(intent);
Log.i("SB",sb.toString());
In Second Activity, the code to load the WebView reads:
WebView browser = ((WebView)findViewById(R.id.trial_web));
browser.getSettings().setJavaScriptEnabled(true);
browser.loadData(html,"text/html", "utf-8");
When I run this code, the WebView is not able to render the HTML content properly. It actually shows the HTML string in URL encoded format on the screen. Interestingly, If I copy the Loggers output to HTML file and then load this HTML in my WebView(using webview.loadurl(file:///assets/xyz.html)) everything works fine.
I suspect some problem with character encoding.
What is going wrong here? Please help.
Thanks.
Try using a BasicResponseHandler rather than converting it all into a string yourself. See here for an example. I am skeptical this will help, but it will simplify your code and let you get rid of the inefficient StringBuffer.
Also, you might try switching to loadDataWithBaseURL(), as I have had poor results with loadData(). The aforementioned example shows this as well.