Posts tagged ‘C#’

September 26, 2010

BHO Development using managed code


Browser Helper Object (BHO) is a plug-in for Internet Explorer (IE). BHO let developers to drive IE. A plug-in is a program which extends the functionality of a browser. It can be used to retrieve information or modify the content of the webpage that is being displayed in a browser window, or it may just be used to provide the user an option to see the day’s Stock market status or, weather in a toolbar.

To start BHO development can be depressing at the very first beginning to learn all those things. As a beginner I want to share my experience to other beginners. Here I am going to explain the simple implementation of BHO.

A Browser Helper Object is a COM object loaded for each IE window. As a browser window is opened, it creates its own copy of the BHO; and, when the window is closed, it destroys its copy of the BHO. You will need a COM dll which interact with browser. This need to done by implementing the IObjectWithSite in class. We need to use COM interop library to implement COM dll in our dotNet project.

While we are writing in C#, we also need to write the interface IObjectWithSite ourselves. Also, we have to then implement the interface in your BHO. To interact with the HTML document, we will need to add a reference to the Microsoft.mshtml library & to get the DOM or the webpage currently in the browser, we will have to add SHDocVw library as a reference. Also, we will have to add 2 functions which will register (& unregister) our COM component as a BHO with Internet Explorer with the key.

Say Hello to BHO development world:

Let’s create a Hello world project regarding BHO. Start a new C# class library project. I named it as ‘HelloBHOWorld’.

read more »

January 12, 2010

Getting execution plan through C#


private void Form1_Load(object sender, EventArgs e)

{

string strConn = “server=Localhost;database=AMT_DB;UID=sa;PWD=”;

SqlConnection conn = new SqlConnection(strConn);

SqlDataReader reader;

conn.Open();

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;

cmd.CommandText = “SET SHOWPLAN_ALL ON”;

cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();

cmd.CommandText = “select * from script S inner join scriptline SL on S.scriptid=SL.scriptid”;

cmd.CommandType = CommandType.Text;

reader = cmd.ExecuteReader();

while (reader.Read())

{

MessageBox.Show(“physicalop ” + reader[4].ToString());

MessageBox.Show(“logicalop ” + reader[5].ToString());

MessageBox.Show(“argument ” + reader[6].ToString());

MessageBox.Show(“estimateio ” + reader[9].ToString());

MessageBox.Show(“estimatecpu ” +reader[10].ToString());

}

cmd.CommandText = “SET SHOWPLAN_ALL OFF”;

cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();

conn.close

}