Strange problem in sending file attachment
-
Hi all, I am getting a strange problem when i try to attach a file with a mail message. Here`s the code.. MailMessage msg=new MailMessage(); msg.To=emailaddr; msg.From=Fromemp; msg.Subject="Hello " ; string attachedFile = UploadCV_File.PostedFile.FileName; MailAttachment ma=new MailAttachment(attachedFile); msg.Attachments.Add(ma); SmtpMail.SmtpServer="localhost"; SmtpMail.Send(msg); The problem is that it gives an error when i select a file path which is long ie C:\Documents and Settings\Administrator\Desktop\New.txt and doesn`t gives an error if the path is short ie C:\New.txt. What`s the problem????Help!!! Thanks in advance
-
Hi all, I am getting a strange problem when i try to attach a file with a mail message. Here`s the code.. MailMessage msg=new MailMessage(); msg.To=emailaddr; msg.From=Fromemp; msg.Subject="Hello " ; string attachedFile = UploadCV_File.PostedFile.FileName; MailAttachment ma=new MailAttachment(attachedFile); msg.Attachments.Add(ma); SmtpMail.SmtpServer="localhost"; SmtpMail.Send(msg); The problem is that it gives an error when i select a file path which is long ie C:\Documents and Settings\Administrator\Desktop\New.txt and doesn`t gives an error if the path is short ie C:\New.txt. What`s the problem????Help!!! Thanks in advance
The spaces are what's killing you. Try replacing the spaces with the ascii equivalent.
-
Hi all, I am getting a strange problem when i try to attach a file with a mail message. Here`s the code.. MailMessage msg=new MailMessage(); msg.To=emailaddr; msg.From=Fromemp; msg.Subject="Hello " ; string attachedFile = UploadCV_File.PostedFile.FileName; MailAttachment ma=new MailAttachment(attachedFile); msg.Attachments.Add(ma); SmtpMail.SmtpServer="localhost"; SmtpMail.Send(msg); The problem is that it gives an error when i select a file path which is long ie C:\Documents and Settings\Administrator\Desktop\New.txt and doesn`t gives an error if the path is short ie C:\New.txt. What`s the problem????Help!!! Thanks in advance
It may sound silly, but try preceding your file path string with the @ symbol... ascii should work too.
Nila
-
The spaces are what's killing you. Try replacing the spaces with the ascii equivalent.
Sorry!!!, but replacing spaces with ascii code also doesn`t work .Here is what i did... MailMessage msg=new MailMessage(); string filename=File1.PostedFile.FileName; filename.Replace(" "," "); attachment=new MailAttachment(filename); msg.To=To_usr.Text; msg.From=From_usr.Text; msg.Body=TextBody.Text; msg.Attachments.Add(attachment); SmtpMail.SmtpServer = "127.0.0.1"; SmtpMail.SmtpServer.Insert(0,"127.0.0.1"); SmtpMail.Send(msg); Is this approach right?? What should i do now?
-
Sorry!!!, but replacing spaces with ascii code also doesn`t work .Here is what i did... MailMessage msg=new MailMessage(); string filename=File1.PostedFile.FileName; filename.Replace(" "," "); attachment=new MailAttachment(filename); msg.To=To_usr.Text; msg.From=From_usr.Text; msg.Body=TextBody.Text; msg.Attachments.Add(attachment); SmtpMail.SmtpServer = "127.0.0.1"; SmtpMail.SmtpServer.Insert(0,"127.0.0.1"); SmtpMail.Send(msg); Is this approach right?? What should i do now?
Well, if it's working then it's right. If not... Try doing a Response.Write(File1.PostedFile.Filename); See what it's actually getting. Response.Write should output it to the very top of your web page. You can also use System.Diagnostics and then do a Debug.Write(File1.PostedFile.FileName);
-
Well, if it's working then it's right. If not... Try doing a Response.Write(File1.PostedFile.Filename); See what it's actually getting. Response.Write should output it to the very top of your web page. You can also use System.Diagnostics and then do a Debug.Write(File1.PostedFile.FileName);
-
Well i did Response.write but it still shows spaces and hence gives invalid attachment error.I can`t use the alternative of copying the file on server and then attaching it to the mail message.
Have you given appropriate permissions to ASP to do this? You need to give IIS IUSR and IIS IWPD the correct permissions so they can write files to the server. Oops, never mind. I was thinking we were uploading to the server... Have you let someone else test your site from another PC to see if the have the problem?
-
Have you given appropriate permissions to ASP to do this? You need to give IIS IUSR and IIS IWPD the correct permissions so they can write files to the server. Oops, never mind. I was thinking we were uploading to the server... Have you let someone else test your site from another PC to see if the have the problem?