Saturday, April 30, 2005

Sending Links in the Email

Sometimes we need to send only the links in email. These links can be of different websites or what so ever.
If you are using the full path or the url than you will have no trouble in concatenating the path to the StringBuilder object and sending it in the email. But that might not be a good idea since the full path is really ugly and most of the people won't understand that what the link represents.

If you have a "Name" column in your database and "Url" column in your database than you can merge both of them and form a link which is more readable since it contains the name which explains much better that what is the link about. In this small code samples I have three columns in datagrid. First is the "Name" column, Second is "Url" and finally the checkbox column. Checkbox column is used if you need to send multiple links.

StringBuilder str = new StringBuilder();

HyperLink hyper = new HyperLink();

foreach(DataGridItem dgi in myDataGrid.Items)
{
CheckBox myCheckBox = (CheckBox) dgi.Cells[2].Controls[1];

hyper = (HyperLink) dgi.Cells[1].Controls[0];

if(myCheckBox.Checked == true)
{

// This generates a string and formats the string
str.Append("");
str.Append(dgi.Cells[0].Text);
str.Append("
");
str.Append("
");

}
}

// Send the email
Email email = new Email();
int result = email.SendEmail(txtEmail.Text ,str.ToString());


3 comments:

Anonymous said...

How in the heck can a non code writing person accomplish this task. This makes absolutely know sense. Is MS hotmail insane?

Anonymous said...

Help

azamsharp said...

I Don't understand what you are trying to say Sir.