well, I am building an update application for my project,and the way i'm checking if there are new updates is by a webBrowser. Here is the function that checks for updates (it's called by the OnDocumentCompleted event):
Code:
void Check()
{
string content = webBrowser1.DocumentText;
string[] checking = content.Split('|');
string data = checking[1];
if (data != "_MTL_VERSIONS_EQUAL_")
{
ProcessData(data);
if(MessageBox.Show("Znaleziono w internecie poprawkę, z wersji aktualnej - "+version+", na "+upVersion+". Czy chcesz ją pobrać?", "Łatki - Multitool Update", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
MessageBox.Show("Za chwilę rozpocznie się pobieranie i instalacja łatki.", "Łatki - Multitool Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
RegistryKey rejestr=Registry.CurrentUser.OpenSubKey("software\\multitool\\UpDate",true);
fPath = Convert.ToString(rejestr.GetValue("DownPath"));//tymczasowa zmiana
button2.Text="Anuluj";
thr=new Thread(new ThreadStart(Download));
thr.Start();
}
else
{
Application.Exit();
}
}
else
{
MessageBox.Show("Nie znaleziono żadnych poprawek.","Łatki - Multitool Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
void WebBrowser1DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
{
thr=new Thread(new ThreadStart(Check));
thr.Start();
}
(sorry the messages are in Polish)
and it gives out an error:
An unhandled exception of type 'System.InvalidCastException' occurred in System.Windows.Forms.dll
Additional information: Specified cast is not valid.
The error is in the line:
string content = webBrowser1.DocumentText;
The documentText value is string so why is it giving out the error?
Please answer quickly.