views:

116

answers:

1

Our company has a intranet based website using which we have to place request for conference calls, every time we have to place a request we have to get the details of persons from Outlook properties and fill in the form. To overcome this, I am creating a Outlook Add in, which will open the website using .NET WebBrowser control , fill in the required data from LDAP and submit the page, all the information will flow from Meeting request page. The problem is that Website needs a post back to load few extra controls based on the data entered on click of a button, but when I try to click that button dynamically, webBrowser_DocumentCompleted event is called properly but the page does not seem to refresh properly, in ideal case I would expect new controls to be present in the page, but the webBrower control still shows me old page.

Any pointer if I can achieve same functionality in some other way or of there is anything I need to do to get this fixed.

Please note that I cannot change the way intranet Website behaves. I am using .NET 3.5 and Outlook 2007

Initializaton code snippet 

WebBrowser wbBuzzConf = new WebBrowser();
wbBuzzConf.Url =  new Uri(ConfigurationManager.AppSettings.Get("ConfAddress"), System.UriKind.Absolute);
wbBuzzConf.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wbBuzzConf_DocumentCompleted);


void wbBuzzConf_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            try
            {                
                WebBrowser wbBuzzConf = sender as WebBrowser;

//       Check if new controls are loaded 
                if (wbBuzzConf.Document.GetElementById("txtEmailOut1") != null)
                {

                }
                else
                {
                    wbBuzzConf.Document.GetElementById("txtNoOfDialOuts").InnerText = users.Count > 5 ? "5" : users.Count.ToString();
                    //DO POST BACK TO LOAD NEW CONTROLS
  wbBuzzConf.Document.GetElementById("imbtGo").InvokeMember("click");

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

    }
A: 

This works for me with IE8 installed.

Test HTML:

<html>
   <body>
     <a href='http://www.cnn.com'&gt;CNN&lt;/a&gt;
     <a id='stackoverflow' href='http://stackoverflow.com'&gt;stackoverflow&lt;/a&gt;
   </body>
</html>

Code:

    void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        WebBrowser webBrowser = sender as WebBrowser;
        foreach (HtmlElement link in webBrowser.Document.Links)
        {
            if(link.Id == "stackoverflow")
            {
                link.InvokeMember("Click");
            }
        }           
    }

If that doesn't work you can try finding the form and invoke Submit on it and see if that helps.

Mikael Svenson