C# .NET - File not found in e-mail attachment - Asked By Dom Afonso on 30-Aug-12 06:02 PM

I am bulding an asp.net application for e-mail sending. Right now I can send e-mail with attachment when I test my application from visual web developer.
But when I deploy it to production web server, I can only send e-mail without attachment because I saparated the methods for sending e-mail without attachment and sending e-mail with attachment.

The erroe I get is the one below:

Server Error in '/' Application.

Could not find file 'c:\windows\system32\inetsrv\Gotu.docx'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\Gotu.docx'.

Source Error: 

Line 83:         if (atalho1 != "")
Line 84:         {
Line 85:             mail.Attachments.Add(new Attachment(File1.Value.ToString()));
Line 86:         }
Line 87:         

Source File: d:\WEB DO CFPCC\Enviar E-Mail.aspx.cs    Line: 85 

Stack Trace: 

[FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\Gotu.docx'.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +12898679
   System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +2481
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +229
   System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +102
   System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName, String mediaType) +110
   System.Net.Mail.Attachment..ctor(String fileName) +25
   _Default.EnviarEMailComAtalho() in d:\WEB DO CFPCC\Enviar E-Mail.aspx.cs:85
   _Default.VerSeTemAtalhoEEnviarEMail() in d:\WEB DO CFPCC\Enviar E-Mail.aspx.cs:194
   _Default.enviarEMailButton_Click(Object sender, EventArgs e) in d:\WEB DO CFPCC\Enviar E-Mail.aspx.cs:36
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707

Can anyone help me solve this?
Peter Bromberg replied to Dom Afonso on 31-Aug-12 05:36 PM
If 'c:\windows\system32\inetsrv\Gotu.docx' is not the actual location of your file attachment, then you need to specify the actual location., Why is this so difficult to understand? The exception message is quite clear.
Rohan Dave replied to Dom Afonso on 01-Sep-12 03:04 PM
There may be two possibilities

1) File is not at that location. So make sure you have file on that given location

2) It may be possible that your C:\Windows\System32\inetserv doesn't have access rights. or this location have some access rights due to this it's not accessible by anywhere.