Internet Explorer object "Object reference not set to an instance of an object."
I've been trying to write an aplication to automatically log me in to facebook, pointless i know but it's a step to a greater goal. Anyway, here's the sticking point:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SHDocVw;
namespace SpamThis
{
public partial class Form1 : Form
{
string UserNames = "";
string Passwords = "";
InternetExplorer Browser;
HtmlDocument Doc;
public Form1()
{
InitializeComponent();
}
private void UserName_TextChanged(object sender, EventArgs e)
{
UserNames = UserName.Text;
}
private void Password_TextChanged(object sender, EventArgs e)
{
Passwords = Password.Text;
}
private void Login_Click(object sender, EventArgs e)
{
Browser = new InternetExplorer();
object o = null;
Browser.Visible = true;
Browser.AddressBar = false;
Browser.Navigate("http://www.facebook.com/", ref o, ref o, ref o, ref o);
while (Browser.Busy)
{
}
Doc.GetElementById("reg_email__").SetAttribute("reg_email__", UserNames);
}
}
}
The line highlighted in red gives me this error: "Object reference not set to an instance of an object."
And then when i try adding this line just above it: Doc = (HtmlDocument)Browser.Document;
it says that i can not convert to this type. How do i retrieve and edit the instance of IE's html document?
Is this the correct way to implement this code? Can anyone help?
Much appreciated