I am testing a simple method to send an attachment in an email. I created a website on my localhost and have included a sample txt file in the root directory of the site.
In my page, I'm calling the following method shown in the code section below.
When I run my page, I get the following error:
Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\TestAttach
The file is not located in the above directory.
I thought that if the file is found in the website, I didn't need to use an explicit file path. I guess I do.
How can I map the path to my file?
I was reading some articles that mentioned using Server.MapPath. However, when I tried this, the intellisense was not finding the Server object and MapPath method.
I also tried HttpServerUtility namespace, but the MapPath member was not available.
I'm using VS2008.
Thanks for any help.
static void AttachmentFromFile()
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("firstname.lastname@example.org");
//set the content
mail.Subject = "This is an email";
mail.Body = "this content is in the body";
//add an attachment from the filesystem
//send the message
SmtpClient smtp = new SmtpClient("xxx.xxx.xxxxxxx.xxxx");
protected void btnSend_Click(object sender, EventArgs e)