I created a winForm application which fills the fields of a web site :
private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate(new Uri("http://www.site.com”));
this.textBox1.Text = this.webBrowser1.Version.ToString();
}
private void button1_Click (object sender, EventArgs e)
{
System.Windows.Forms.HtmlDocument document =
this.webBrowser1.Document;
document.GetElementById("login").SetAttribute("Value","user");
}
It works perfectly when the web site page is loaded in application control but when I want to open it in a new browser using webBrowser1.Navigate(new Uri("http://www.site.com”),true); the page fields are undetectable.
Is there a solution for this problem? Thanks in advance
Related
I have a project that reads content from web and saves it to the database.
I use Timer control to wait for ajax changes and it has been working for a long time without any problem.
But unexpectedly it is not working any more. I get the following error :
Exception thrown: 'System.Runtime.InteropServices.COMException' in
SnapshotInfo.exe
Additional information: Error HRESULT E_FAIL has been returned from a
call to a COM component.
Part of the code on this problem :
WebBrowser _browser = new WebBrowser();
private void Form1_Load(object sender, EventArgs e)
{
_browser.Dock = DockStyle.Fill;
_browser.DocumentCompleted += _browser_DocumentCompleted;
Controls.Add(_browser);
}
private void _browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!timer1.Enabled)
{
// do any thing
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
_browser.Dispose();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (_browser.Document==null || _browser.Document.Body==null) return;
var body = _browser.Document.Body.InnerHtml; // ----> error here
if (body.Contains("word"))
{
// code when word is exist
timer1.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
_browser.Navigate(textBox1.Text);
timer1.Enabled = true;
}
I do not know where is the problem?
Thanks for any help
Make sure you are using latest version of web browser control , check below link
Use latest version of Internet Explorer in the webbrowser control
or you can replace web browser control with another web browser engine like http://www.awesomium.com/ it's free and easier to use
The problem solved by deleting the security update KB3087040!
I have a very simple program that has 4 buttons each button opens a url.
What i would like is to get each button to use Firefox as the default browser.
I know i can set it as the default browser and then it will work however if a user sets internet explorer as the defualt it will open in that instead.
These url only work in Firefox as it has certificate issues.
So essentially my question is how can i change my code to make sure that if you click on any of the 4 buttons, that it will open up in firefox and not internet explorer.
Here is my code
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://192.168.2.56/dummy.htm?settings=save&user_active1=on");
BtnOff.BackColor = Color.Red;
Bnton.BackColor = Color.Chartreuse;
}
private void button2_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://192.168.2.56/dummy.htm?settings=save&user_active1=off");
Bnton.BackColor = Color.Red;
BtnOff.BackColor = Color.Chartreuse;
}
private void button3_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://217.20.xxx.xxx/api/agent/pause.json?active_host=217.20.xxx.xxx&active_user=3012532&username=buildstore&password=cha9pU7U&client=snom");
BtnDND.BackColor = Color.Chartreuse;
BtnQue.BackColor = Color.Red;
}
private void button4_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("https://217.20.xxx.xxx/api/agent/unpause.json?active_host=217.20.xxx.xxx&active_user=3012532&username=buildstore&password=cha9pU7U&client=snom");
BtnQue.BackColor = Color.Chartreuse;
BtnDND.BackColor = Color.Red;
}
Thanks for taking the time to look appreciate it.
you can use
System.Diagnostics.Process.Start(#"C:\Program Files (x86)\Mozilla Firefox\firefox.exe", "http://yoursite.com/dummy.htm");
you can keep the path of firefox.exe in config file instead of hard coding. Alternatively set the PATH environment variable.
I am currently using a simple button to open a webpage.
void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca");
}
What I want to do is get it to open 3 pages at once with the one click and I am having a hard time getting it to work. I have tried multiple Process.start lines
void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca");
System.Diagnostics.Process.Start("http://www.gmail.com");
System.Diagnostics.Process.Start("http://www.stackoverflow.com");
}
and even adding multiple pages into the handler.
void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca","http://www.gmail.com","http://www.s tackoverflow.com")
}
It will only open the last page in the list in both cases. Any ideas?
If IE is open, your code works fine and opens each link in a new tab, if not, I was able to make it work by making the app wait for 1 sec before calling the second page to open:
void ReportingClick(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://www.google.ca");
System.Threading.Thread.Sleep(1000);
System.Diagnostics.Process.Start("http://www.gmail.com");
System.Threading.Thread.Sleep(1000);
System.Diagnostics.Process.Start("http://www.stackoverflow.com");
}
Could you show me how to bind textBox1 (Address Bar) to webBrowser1 (Web Page) so what ever the user navigates to on the page will show in the box? Or is their another way to do this?
You can have the events for WebBrowser like DocumentCompleted, Navigating, Navigated,
Please see the sample code , let me know if you have any queries.
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("http://www.google.com");
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
textBox1.Text = webBrowser1.Url.ToString();
}
I have created a web browser in c#
this was what i get when i opened my web browser and typed google. Then i searched google for something
the result was like this
But the url wasn't updated in address bar. How to update the address bar when user click on a link on any website in my web browser
In the first image the url was google.com
In the second image url was https://www.google.co.in/#hl=en&output=search&sclient=psy-ab like that some thing but it wasn't updated
You must update the textbox on top with the URL of the WebBrowserControl, using the webBrowser1_Navigating event.
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
textbox1.text = webBrowser1.Url.ToString();
}
Check http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser_events.
I think you can use Navigating event to detect when user starts search or navigates to another page.
The Form_Load must contain this:
private void Form1_Load(object sender, EventArgs e)
{
web = new WebBrowser();
web.Navigated += web_Navigated;
}
and this function:
private void web_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
textBox1.Text = web.Url.ToString();
}