0

Hi,
I have a excel file with 1000mail Id's i want to send the greetings to them at a time by splitting their names
Example: if.ex@gmail.com the mail should go as "Hi ex".For this i want to upload event or property to upload the excel file.

can u please help me

4
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by inplainsite
0

There are several ways of doing this, the one that Microsoft reccomends against doing is using the office interopt. If it's an excel 2007 or newer file, you can open it like its a zip file and parse through the xml contents from there (System.IO, System.IO.Packaging namespaces)

0

First need to upload excel sheet(email Id's) to the application. Here i give sample code how its work. If this not use tel me clear idea about exact requirement.

// browse excel file in text box 
                string str = txtExcelName.Text;
                str = str.Replace("/", "//");

		//conn to the excel sheet

                string connstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + str + ";Extended Properties=Excel 8.0";

                OleDbConnection conn = new OleDbConnection(connstr);
                objConn = new OleDbConnection(connstr);

                objConn.Open();

                dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

		// write the quesry to fetch email from excel, "Table name is youe excel sheet and Email is tap name in youe excel
                string strSQL = "SELECT Email FROM [" + dt.Rows[0]["Table_Name"].ToString() + "]";
                
                objConn.Close();
                OleDbCommand cmd = new OleDbCommand(strSQL, conn);
                DataSet ds = new DataSet();
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);

		// fetching and put in to datatable
                da.Fill(ds, "Mob");
                DataTable dtt = ds.Tables["Email"];
                dtt = RemoveDuplicateRows(dtt, "Email");

                if (ds.Tables["Email"].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables["Email"].Rows.Count; i++)
                    {
                        string em = ds.Tables["Email"].Rows[i]["EamilId"].ToString();
                        //spilt the text with @ simple
			string[] words = em .Split('@');
			// Now YOU GET THE FIRST WORD 
			string result = words[0];

                    }
                    
                }

Hope this will give you some idea...

Edited by __avd: Added [code] tags.

0

Hi
I have tried this code but there are some errors in it.

First need to upload excel sheet(email Id's) to the application. Here i give sample code how its work. If this not use tel me clear idea about exact requirement.

// browse excel file in text box 
                string str = txtExcelName.Text;
                str = str.Replace("/", "//");

		//conn to the excel sheet

                string connstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + str + ";Extended Properties=Excel 8.0";

                OleDbConnection conn = new OleDbConnection(connstr);
                objConn = new OleDbConnection(connstr);

                objConn.Open();

                dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

		// write the quesry to fetch email from excel, "Table name is youe excel sheet and Email is tap name in youe excel
                string strSQL = "SELECT Email FROM [" + dt.Rows[0]["Table_Name"].ToString() + "]";
                
                objConn.Close();
                OleDbCommand cmd = new OleDbCommand(strSQL, conn);
                DataSet ds = new DataSet();
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);

		// fetching and put in to datatable
                da.Fill(ds, "Mob");
                DataTable dtt = ds.Tables["Email"];
                dtt = RemoveDuplicateRows(dtt, "Email");

                if (ds.Tables["Email"].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables["Email"].Rows.Count; i++)
                    {
                        string em = ds.Tables["Email"].Rows[i]["EamilId"].ToString();
                        //spilt the text with @ simple
			string[] words = em .Split('@');
			// Now YOU GET THE FIRST WORD 
			string result = words[0];

                    }
                    
                }

Hope this will give you some idea...

0

Why don't you just save the excel file as a CSV?(Comma Separated Values) This way you can import the CSV basically as a string and the split the string on commas. Then you will have an array of the emails.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.