Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Strange problem in sending file attachment

Strange problem in sending file attachment

Scheduled Pinned Locked Moved ASP.NET
helpquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NetBot
    wrote on last edited by
    #1

    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

    C G 2 Replies Last reply
    0
    • N NetBot

      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

      C Offline
      C Offline
      code frog 0
      wrote on last edited by
      #2

      The spaces are what's killing you. Try replacing the spaces with the ascii equivalent.

      W 1 Reply Last reply
      0
      • N NetBot

        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

        G Offline
        G Offline
        Grapes R Fun
        wrote on last edited by
        #3

        It may sound silly, but try preceding your file path string with the @ symbol... ascii should work too.

        Nila

        1 Reply Last reply
        0
        • C code frog 0

          The spaces are what's killing you. Try replacing the spaces with the ascii equivalent.

          W Offline
          W Offline
          www Developerof NET
          wrote on last edited by
          #4

          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?

          C 1 Reply Last reply
          0
          • W www Developerof NET

            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?

            C Offline
            C Offline
            code frog 0
            wrote on last edited by
            #5

            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);

            N 1 Reply Last reply
            0
            • C code frog 0

              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);

              N Offline
              N Offline
              NetBot
              wrote on last edited by
              #6

              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.

              C 1 Reply Last reply
              0
              • N NetBot

                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.

                C Offline
                C Offline
                code frog 0
                wrote on last edited by
                #7

                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?

                N 1 Reply Last reply
                0
                • C code frog 0

                  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?

                  N Offline
                  N Offline
                  NetBot
                  wrote on last edited by
                  #8

                  The app is still under construction and hasn`t been uploaded on a server.It`s still on my PC.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups