469,889 Members | 1,244 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,889 developers. It's quick & easy.

Access to the path is denied.

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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_Length).ToString()+
" Bytes");
}
}

Oct 16 '06 #1
1 3099
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

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"Santosh" <Sa***************@yahoo.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_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(strFi le_Name));
dt =
addmyRow(dt,strFile_Name,Convert.ToInt32(attachFil e_Length).ToString()+
" Bytes");
}
}

Oct 16 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Theerachet Pratoommanee | last post: by
4 posts views Thread by Fabian von Romberg | last post: by
3 posts views Thread by Shailesh Humbad | last post: by
1 post views Thread by Duffman | last post: by
3 posts views Thread by David Thielen | last post: by
2 posts views Thread by stephen | last post: by
1 post views Thread by cpajoe2001 | last post: by
8 posts views Thread by Jeremy Ames | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.