Email with Attachment

Posted by Venkat | Labels:

Now we will see , how to send an attachment to the email.

for the you have to create an instance for Attachment class and pass the filename and specify the media type information for an email message attachements and set the ContentDisposition which specify the file type whether its txt , doc, gif,jpg etc..,

Import NameSpace

using System.Net.Mail;
using System.Net.MIME;
using System.Net;

Code

try
{

MailMessage mail = new MailMessage();

mail.To.Add("venkat@gmail.com");

mail.From = new MailAddress("admin@Support.com");

mail.Subject = "Testing Email Attachment";

string file = Server.MapPath("~/files/findemai_ontextfile.txt");

Attachment attachFile = new Attachment(file, MediaTypeNames.Application.Octet);

ContentDisposition disposition = attachFile.ContentDisposition;

mail.Attachments.Add(attachFile);

SmtpClient smtp = new SmtpClient();

smtp.Host = "smtp.gmail.com";

smtp.EnableSsl = true;

smtp.Credentials = new NetworkCredential("xxxxxxx@gmail.com", "*********");
s;

smtp.Send(mail);

}

catch (Exception ex)
{

Response.Write(ex.Message);

}

This link helps you :
http://msdn.microsoft.com/en-us/library/system.net.mail.attachment.aspx

Checkboxlist sample code

Posted by Venkat | Labels: ,

Now we are going to discuss about the Checkbox list Control so Checkboxlist allows user to select Multiple values , we will see how to retrieve the selected values from the Checkboxlist.

Here is the HTML Code


<asp:CheckBoxList ID="cblPlanets" runat="server" Width="109px">
<asp:ListItem Value="1">Mercury</asp:ListItem>
<asp:ListItem Value="2">Venus</asp:ListItem>
<asp:ListItem Value="3">Earth</asp:ListItem>
<asp:ListItem Value="4">Mars</asp:ListItem>
<asp:ListItem Value="5">Jupiter</asp:ListItem>
<asp:ListItem Value="6">Saturn</asp:ListItem>
<asp:ListItem Value="7">Uranus</asp:ListItem>
<asp:ListItem Value="8">Neptune</asp:ListItem>
</asp:CheckBoxList>
in Code behind , then place one label control to get the selectedvalue of checkboxlist

C# SOURCE

protected void btnSubmit_Click(object sender, EventArgs e)
{
lblText.Text = "You selected: ";

foreach (ListItem li in cblPlanets.Items)
{
if (li.Selected == true)
{
lblText.Text = lblText.Text += "~" + li.Text;
}
}
}

PayOffers.in