Access to the path is denied.

S

Santosh

Hii i am writting following code for attaching file to the emails it
runs well on the local server but when i run it on domain servert then
it gives an error Access to the path is denied.
can any one tell me what is the problem in it.

public void AttachFilesToEmail(object sender, System.EventArgs e)
{
DataTable dt;
dt = attachedFileTable();
string strFile_Name;
int attachFile_Length;

//if(attachFile_Length==1
if (attachFile1.PostedFile.ContentLength > 0)
{
HttpPostedFile attFile1 = attachFile1.PostedFile;
attachFile_Length = attFile1.ContentLength;
if (attachFile_Length > 0)
{
strFile_Name = Path.GetFileName(attachFile1.PostedFile.FileName);
attachFile1.PostedFile.SaveAs(Server.MapPath(strFile_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFile_Length).ToString()+
" Bytes");
}
}
if (attachFile2.PostedFile.ContentLength > 0)
{
HttpPostedFile attFile1 = attachFile2.PostedFile;
attachFile_Length = attFile1.ContentLength;
if (attachFile_Length > 0)
{
strFile_Name = Path.GetFileName(attachFile2.PostedFile.FileName);
attachFile1.PostedFile.SaveAs(Server.MapPath(strFile_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFile_Length).ToString()+
" Bytes");
}
}
if (attachFile3.PostedFile.ContentLength > 0)
{
HttpPostedFile attFile1 = attachFile3.PostedFile;
attachFile_Length = attFile1.ContentLength;
if (attachFile_Length > 0)
{
strFile_Name = Path.GetFileName(attachFile3.PostedFile.FileName);
attachFile1.PostedFile.SaveAs(Server.MapPath(strFile_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFile_Length).ToString()+
" Bytes");
}

}
if (attachFile4.PostedFile.ContentLength > 0)
{
HttpPostedFile attFile1 = attachFile4.PostedFile;
attachFile_Length = attFile1.ContentLength;
if (attachFile_Length > 0)
{
strFile_Name = Path.GetFileName(attachFile4.PostedFile.FileName);
attachFile1.PostedFile.SaveAs(Server.MapPath(strFile_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFile_Length).ToString()+
" Bytes");
}
}
if (attachFile5.PostedFile.ContentLength > 0)
{
HttpPostedFile attFile1 = attachFile5.PostedFile;
attachFile_Length = attFile1.ContentLength;
if (attachFile_Length > 0)
{
strFile_Name = Path.GetFileName(attachFile5.PostedFile.FileName);
attachFile1.PostedFile.SaveAs(Server.MapPath(strFile_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFile_Length).ToString()+
" Bytes");
}
}
 
C

Cowboy \(Gregory A. Beamer\)

If I can take a guess, you are developing on Windows XP and deploying to
Windows Server 2003. The file you are attempting to attach exists in a
folder outside of the website (instead of something like <root>/attachments
it is c:\attachments).

If so, you have choices:
1. Turn off the transversal security bits and allow the website to read from
any folder (this is also known as "destroy the security of your machine")
2. Set up a windows service to feed the file
3. Move the attachment files to the website directory structure
4. Move the attachment "file" to the database
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top