sunilKUpadhyay

HI,

I am trying to load the data in the webbrowser for my mobile winform application.

I am writting my html content to the text file and setting the webbrowser URL to the filePath.

Data comes up properly for the first time.

Next time by changing data in the file and setting the url of the file to the same filepath and calling the refresh method of the webbroser does not changes the browser content.

Below is the code what i am trying to do.

private System.Windows.Forms.WebBrowser webBrowser;

this.webBrowser = new System.Windows.Forms.WebBrowser();

void UpdateScreenContent()

{

ConstructSampleHtml();

this.webBrowser.Url = this.blankUri;

this.webBrowser.Url = new Uri(this.webBrowserFilePath);

//i had tryed with navigate also but it's not working

//this.webBrowser.Navigate(new Uri(this.webBrowserFilePath));

this.webBrowser.Refresh();

}

/// <summary>

/// Constructs the empty HTML.

/// </summary>

private void ConstructSampleHtml()

{

StringBuilder html = new StringBuilder();

using (XmlTextWriter textWriter = new XmlTextWriter(new StringWriter(html)))

{

WriteHtmlStartingTag(textWriter);

WriteBodyStartingTag(textWriter);

WriteSampleLineDetails(textWriter);

WriteBodyAndHtmlClosingTags(textWriter);

}

this.WriteToHtmlFile(html);

}

/// <summary>

/// Writes the HTML starting tag.

/// </summary>

/// <param name="textWriter">The text writer.</param>

private void WriteHtmlStartingTag(XmlTextWriter textWriter)

{

textWriter.WriteStartElement("html");

}

/// <summary>

/// Writes the body starting tag.

/// </summary>

/// <param name="textWriter">The text writer.</param>

private void WriteBodyStartingTag(XmlTextWriter textWriter)

{

// body tag

textWriter.WriteStartElement("body");

textWriter.WriteAttributeString("oncontextmenu", "return false;");

textWriter.WriteAttributeString("scroll", "auto");

textWriter.WriteAttributeString("style",

"font-family: Tahoma; "

+ "font-size: 9pt; "

+ "color: rgb(102, 102, 102); "

+ "margin-top: 7px; "

+ "margin-left:7px;");

}

/// <summary>

/// Writes the body and HTML closing tags.

/// </summary>

/// <param name="textWriter">The text writer.</param>

private static void WriteBodyAndHtmlClosingTags(XmlTextWriter textWriter)

{

textWriter.WriteEndElement(); // closing body

textWriter.WriteEndElement(); // closing html

}

/// <summary>

/// Writes the HTML to HTML file.

/// </summary>

/// <param name="html">The dummy HTML.</param>

private void WriteToHtmlFile(StringBuilder html)

{

//write to file

using (StreamWriter streamWriter = new StreamWriter(this.webBrowserFilePath, false, Encoding.UTF8))

{

streamWriter.Write(html.ToString());

}

}

private void WriteSampleLineDetails(page pageInfo, XmlTextWriter textWriter)

{

textWriter.WriteString("ID ");

textWriter.WriteString("Name ");

textWriter.WriteString("1 ");

textWriter.WriteString("Sunil");

textWriter.WriteString("2");

textWriter.WriteString("Rakesh");

}



Re: .NET Compact Framework WebBrowser Refresh issue

David Wrighton

There seems to be some sort of cacheing problem. I recommend you choose a different filename for each different content page.

David Wrighton

.NET Compact Framework





Re: .NET Compact Framework WebBrowser Refresh issue

AlxJ

As a quick fix you can create a random number generated each time navigate is called and attach it to the url as a parameter
.Navigate returns a new call to the broswer control only and only if the url is different each time..
So if you want to call http://msdn2.microsoft.com/en-us/default.aspx and not retrieve a cached version each time the navigate is called you should do something like the following

Random rand = new Random();

string url = "call http://msdn2.microsoft.com/en-us/default.aspx"+"&="+ rand.Next(0,10000).ToString();

WebBrowser.Navigate(url);