-Dman100-
asked on
map path to file in website
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 ement.txt' .
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.
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("no-reply@myisphost.net");
mail.To.Add("xxxxxxxxxxxxxx@myisphost.net");
//set the content
mail.Subject = "This is an email";
mail.Body = "this content is in the body";
//add an attachment from the filesystem
mail.Attachments.Add(new Attachment("TestAttachement.txt"));
//send the message
SmtpClient smtp = new SmtpClient("xxx.xxx.xxxxxxx.xxxx");
smtp.Send(mail);
}
protected void btnSend_Click(object sender, EventArgs e)
{
AttachmentFromFile();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for replying to my post. Those were the exact articles I was reading.
I figured out what the problem was. My AttachmentFromFile() method was static.
Why can't you use Server.MapPath in a static method?