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

Recommended Answers

All 4 Replies

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)

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...

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...

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.