Saturday, August 7, 2010

Sending Email With BCC and Attachment in ASP.NET

Let’s see how to send Email with BCC and attachment with ASP.NET.

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Net;

using System.Net.Mail;

using System.IO;

public partial class sendmail : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void btnmail_Click(object sender, EventArgs e)

{

{

string mAttach;

MailMessage msg = new MailMessage();

MailAddress ma = new MailAddress("from email-ID", "Name");

msg.From = ma;

if (txtTo.Text.Trim().Length != 0)

{

msg.To.Add(txtTo.Text);

}

if (txtBcc.Text.Trim().Length != 0)

{

msg.Bcc.Add(txtBcc.Text);

}

if (txtCC.Text.Trim().Length != 0)

{

msg.CC.Add(txtCC.Text);

}

Attachment at = new Attachment(FileResume.PostedFile.InputStream, FileResume.FileName);

msg.Attachments.Add(at);

msg.Subject = txtSubject.Text;

msg.Body = txtMessage.Text;

try

{

SmtpClient smpt = new SmtpClient();

smpt.Host = "Your Server Name";

smpt.Send(msg);

}

catch (Exception ex)

{

}

}

}

}

The System.Net.Mail namespace is the one which contains the classes used to send electronic mail to a Simple Mail Transfer Protocol (SMTP) server for delivery.

SmtpClient class is the one which allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP).

Mail Message is the one that represents an e-mail message that can be sent using the SmtpClient class.

Attachment is the class that represents an attachment to an e-mail.

Monday, August 2, 2010

Convert Url String to Hyperlinks

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Text;
public partial class ReplaceString : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strUrl = MakeUrl("Hello. This is my site http://www.google.com Please Visit.");
Response.Write(strUrl);
}
private static string MakeUrl(string input)
{
var work = input.Split(' ');
var output = new StringBuilder(2 * input.Length);
for (int i = 0; i <>
{
var element = work[i];
if (element.StartsWith("http://"))
{
var site = element.Replace("http://", "");
}
else if (element.StartsWith("www"))
{
var site = element.Replace("http://", "");
}
else if (element.EndsWith(".com"))
{
var site = element.Replace("http://", "");
}
output.Append(element + " ");
}
return output.ToString();
}
}

AutoComplete Extender Content Overridden Issue

While using AutocompleteExtender, we could notice where the other controls are been overridden and the autocomplete extender text being overlapped by the other controls near by.This could be overcome by calling the OnClientShown property of the AutocompleteExtender control.

<cc1:AutoCompleteExtender ID="ace" runat="server" OnClientShown="ShowOptions">

cc1:AutoCompleteExtender>

<script language="javascript" type="text/javascript">

function ShowOptions(control, args) {

control._completionListElement.style.zIndex = 10000001;

}

script>