C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Tips » Web Development »

Attach Files to mail using C#


Posted Date: 23 Oct 2009    Resource Type: Tips    Category: Web Development
Author: kishore chMember Level: Gold    
Rating: 1 out of 5Points: 5



Attach Files to mail using C#

To attach a file, add it to the MailMessage.Attachments AttachmentCollection by calling the MailMessage.Attachments.Add method. The simplest way to add a file is to specify the file name



' VB
Dim m As MailMessage = New MailMessage()
m.Attachments.Add(New Attachment("C:\boot.ini"))

// C#
MailMessage m = new MailMessage();
m.Attachments.Add(new Attachment(@"C:\boot.ini"));

You can also specify a MIME (Multipurpose Internet Mail Extensions) content type using the System.Net.Mime.MediaTypeNames enumeration. There are special MIME types for text and images, but you will typically specify MediaTypeNames.Application.Octet. The following code sample (which requires System.IO and System.Net.Mime in addition to System.Net.Mail) demonstrates how to use a Stream as a file attachment and how to specify the MIME type:

' VB
Dim m As MailMessage = New MailMessage()
Dim sr As Stream = New FileStream("C:\Boot.ini", FileMode.Open, FileAccess.Read)
m.Attachments.Add(New Attachment(sr, "myfile.txt", MediaTypeNames.Application.Octet))

// C#
MailMessage m = new MailMessage();
Stream sr = new FileStream(@"C:\Boot.ini", FileMode.Open, FileAccess.Read);
m.Attachments.Add(new Attachment(sr, "myfile.txt", MediaTypeNames.Application.Octet));






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Attach Files to mail using C#  .  Attach Files to mail  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Bing...........
Previous Resource: Sort DataGridView in Run Time
Return to Discussion Resource Index
Post New Resource
Category: Web Development


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use