Sending Email Asynchronously

Posted by Venkat | Labels: , ,

Good Morning to Everybody this is my First article.
Now i am going to see how to send email Asynchronously, actually we send email normally using asp.net Example check here..
Send Email Using ASP.NET

By default smtpClient has one method called SendAsync to send an email ansynchronously. so if you sending an email normally it will take some time for each mail sent. But if you send an email Asynchronously it will not wait for each mail sent it will do the other process , while mail sending is done at background process.
So Here is the code.

//creating mail message object
 MailMessage mailMessage = new MailMessage();
 mailMessage.From = new MailAddress("venkat@gmail.com");
 mailMessage.To.Add(new MailAddress("msdotnettechies@gmail.com"));
 mailMessage.CC.Add(new MailAddress("user1@gmail.com"));
 mailMessage.Bcc.Add(new MailAddress("user2@gmail.com"));
 mailMessage.Subject = "Email Checking Asynchronously";
 mailMessage.Body = "Email test asynchronous";
 mailMessage.IsBodyHtml = true;//to send mail in html or not

 SmtpClient smtpClient = new SmtpClient();//portno here
 smtpClient.Host = "smtp.gmail.com";
 smtpClient.EnableSsl = true ; //True or False depends on SSL Require or not
 smtpClient.Credentials = new NetworkCredential("yourGmail@gmail.com", "yourpassword");
 //smtpClient.UseDefaultCredentials = true; //true or false depends on you want to default credentials or not
 Object mailState = mailMessage;

 //this code adds event handler to notify that mail is sent or not
 smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
 try
 {
 smtpClient.SendAsync(mailMessage, mailState);
 }
 catch (Exception ex)
 {
 Response.Write(ex.Message);
 Response.Write(ex.StackTrace);
 }

// this is the event called on main method
void smtpClient_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
 {
 MailMessage mailMessage = e.UserState as MailMessage;
 if (e.Cancelled || e.Error != null)
 {

 Response.Write(e.Error.Message);
 Response.Write(e.Error.StackTrace);
 }
 else
 {
 Response.Write("Email sent successfully");
 }
 } 
 

Ref :  http://jalpesh.blogspot.com/2010/02/how-to-send-mail-asynchronously-in.html

Sams Teach Yourself ASP.NET 3.5 in 24 Hours, Complete Starter Kit How to Train Your DragonHarry Potter Box Set

Logout issue : Copy the URL of the user page and paste user after logout show the page only IE has Issue

Posted by Venkat | Labels: , ,

When i working on the project ,i faced the issue - that i am sharing to u. ex: When the user login in to his account then do some navigation inside User page - at this stage I copied the URL then i Click Logout button. 

Once i logged out if i paste the Copied URL on that page it redirect to the user Page, when i do some navigation (or clicking any button on that page ) its has been redirect to Login page , but this should not occur  like this if i paste the URL it will directly redirect to the Login page only.This issue will not occur on Mozilla , IE 8 version. it occurs only on IE  browser.

Even if  I set the Session on page_load event but no use. So the thing is Cache ie: the page has been cached stored on Client Browser, so we need to disable the cache.

So Add this line on Master Page inside the Head Tag.

 <meta http-equiv="PRAGMA" value="NO-CACHE"></meta>
<meta content="Mon, 01 Jan 1990 12:00:00 GMT" http-equiv="Expires"></meta>



 
 

uploading text and numeric data from an excel file shows NULL Value

Posted by Venkat | Labels: , ,

Good Morning to everyone

I was working with one of the project , where i had the task of uploading excel ie: Read the Excel data to Dataset ie: from DataSet I am going to store the each field value to DB, so the excel sheet may contain numbers ,or string ,.. by default the Excel sheet  accept  the data based on the first rows of excel sheet.

If the first row and first column will be string - so further the whole first rows and first columns accept strings, if there is any Numeric found  on the first rows and first columns it consider as NULL ie: Empty value , as the same for Numeric also so it may also contain alphanumeric on some cells.

So while we read the Excel sheet  these problems are arise. then we tried to select all cell ie: full excel sheet -> Right Click on the Excel sheet - > format Cells - > Choose String - > click ok .Then I upload this Excel sheet to Read the Data.

Why we change the Format cell  to String means if we set it as string it will accept as both numeric , strings , or alphanumeric - so i am going end it up by doing this.

But the problem arises again - it works that time correctly after few day the same problem occurs, then i do some research or googled and came up with a solution :

The short answer is "IMEX=1" 

You have to apply this on Connection String

To connect to an excel file within ADO.NET use the "System.Data.OleDb" provider  a connection string similar to:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source="Sample.xls";Persist Security Info=False;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1" 

 Thanks for All. 

 

PayOffers.in