Re: SMTP Mail Attachments: filenames with spaces don't work

Discussion in 'ASP .Net' started by Scott Allen, Aug 21, 2004.

  1. Scott Allen

    Scott Allen Guest

    Hi Nicholas:

    Be careful with escape sequences, which start with a '\'. For
    instance, "\T" in your code represents a single tab character.

    You have to either escape the '\' character with another '\', or make
    the string a verbatim string literal.

    i.e.

    "c:\\Test Document.txt"

    or

    @"c:\Test Document.txt"

    HTH,

    --
    Scott
    http://www.OdeToCode.com

    On Fri, 20 Aug 2004 14:09:02 -0700, "Nicholasp27"
    <> wrote:

    >I am trying to have a webform email a user using smtp and be able to attach a
    >document(s). It works if the document is something like "c:\test.txt" but if
    >it is "c:\My Documents\user\desktop\test.txt" it gives an error. How do I
    >fix this?
    >
    >Here's code that works if it's c:\testdocument.txt but not if it's c:\test
    >document.txt
    >
    >Dim mailAttachment As Mail.MailAttachment
    > Try
    > mailAttachment = New Mail.MailAttachment("c:\Test Document.txt")
    > email.Attachments.Add(mailAttachment)
    > System.Web.Mail.SmtpMail.SmtpServer = "smtp.servername.com"
    > System.Web.Mail.SmtpMail.Send(email)
    >
    >Thanks
     
    Scott Allen, Aug 21, 2004
    #1
    1. Advertising

  2. thanks for response. i'll try that
    however, why does that make it work when it's c:\testdoc.txt but not c:\test
    doc.txt?

    it works if no spaces, doesn't if spaces

    also, i am using an html control filebox that allows user to browse to
    file...i was just showing literal string to illustrate here...to me, it seems
    if the browser can find it by browsing, it should work in attaching...but it
    doesn't if space in name, does if no spaces

    "Scott Allen" wrote:

    > Hi Nicholas:
    >
    > Be careful with escape sequences, which start with a '\'. For
    > instance, "\T" in your code represents a single tab character.
    >
    > You have to either escape the '\' character with another '\', or make
    > the string a verbatim string literal.
    >
    > i.e.
    >
    > "c:\\Test Document.txt"
    >
    > or
    >
    > @"c:\Test Document.txt"
    >
    > HTH,
    >
    > --
    > Scott
    > http://www.OdeToCode.com
    >
    > On Fri, 20 Aug 2004 14:09:02 -0700, "Nicholasp27"
    > <> wrote:
    >
    > >I am trying to have a webform email a user using smtp and be able to attach a
    > >document(s). It works if the document is something like "c:\test.txt" but if
    > >it is "c:\My Documents\user\desktop\test.txt" it gives an error. How do I
    > >fix this?
    > >
    > >Here's code that works if it's c:\testdocument.txt but not if it's c:\test
    > >document.txt
    > >
    > >Dim mailAttachment As Mail.MailAttachment
    > > Try
    > > mailAttachment = New Mail.MailAttachment("c:\Test Document.txt")
    > > email.Attachments.Add(mailAttachment)
    > > System.Web.Mail.SmtpMail.SmtpServer = "smtp.servername.com"
    > > System.Web.Mail.SmtpMail.Send(email)
    > >
    > >Thanks

    >
    >
     
    =?Utf-8?B?TmljaG9sYXNwMjc=?=, Aug 21, 2004
    #2
    1. Advertising

  3. it works!

    thanks!!!

    i'm still unsure why it worked with no spaces but didn't with spaces, but
    just replacing "\" with "\\" works and so i'm happy

    thanks again!


    "Nicholasp27" wrote:

    > thanks for response. i'll try that
    > however, why does that make it work when it's c:\testdoc.txt but not c:\test
    > doc.txt?
    >
    > it works if no spaces, doesn't if spaces
    >
    > also, i am using an html control filebox that allows user to browse to
    > file...i was just showing literal string to illustrate here...to me, it seems
    > if the browser can find it by browsing, it should work in attaching...but it
    > doesn't if space in name, does if no spaces
    >
    > "Scott Allen" wrote:
    >
    > > Hi Nicholas:
    > >
    > > Be careful with escape sequences, which start with a '\'. For
    > > instance, "\T" in your code represents a single tab character.
    > >
    > > You have to either escape the '\' character with another '\', or make
    > > the string a verbatim string literal.
    > >
    > > i.e.
    > >
    > > "c:\\Test Document.txt"
    > >
    > > or
    > >
    > > @"c:\Test Document.txt"
    > >
    > > HTH,
    > >
    > > --
    > > Scott
    > > http://www.OdeToCode.com
    > >
    > > On Fri, 20 Aug 2004 14:09:02 -0700, "Nicholasp27"
    > > <> wrote:
    > >
    > > >I am trying to have a webform email a user using smtp and be able to attach a
    > > >document(s). It works if the document is something like "c:\test.txt" but if
    > > >it is "c:\My Documents\user\desktop\test.txt" it gives an error. How do I
    > > >fix this?
    > > >
    > > >Here's code that works if it's c:\testdocument.txt but not if it's c:\test
    > > >document.txt
    > > >
    > > >Dim mailAttachment As Mail.MailAttachment
    > > > Try
    > > > mailAttachment = New Mail.MailAttachment("c:\Test Document.txt")
    > > > email.Attachments.Add(mailAttachment)
    > > > System.Web.Mail.SmtpMail.SmtpServer = "smtp.servername.com"
    > > > System.Web.Mail.SmtpMail.Send(email)
    > > >
    > > >Thanks

    > >
    > >
     
    =?Utf-8?B?TmljaG9sYXNwMjc=?=, Aug 23, 2004
    #3
  4. Scott Allen

    Scott Allen Guest

    I'm glad you figured it out!

    --
    Scott

    On Mon, 23 Aug 2004 07:09:02 -0700, "Nicholasp27"
    <> wrote:

    >WAIT
    >HOLD UP
    >
    >that wasn't it at all!
    >
    >i had to upload the file to the server first! the server can't find that
    >file path cause it doesn't exist on the server (was running locally on comp
    >so it still found c: but not the desktop path)
    >
    >
    >This works:
    >
    >Dim file1 As String = System.IO.Path.Combine(System.IO.Path.GetTempPath,
    >System.IO.Path.GetFileName(dialog1.Value))
    >
    >dialog1.PostedFile().SaveAs(file1)
    >
    >mailattachment1= new mail.mailattachment(file1)
    >
    >{dialog1 is the file browser box under html controls in vb.net}
    >
    >
    >"Nicholasp27" wrote:
    >
    >> it works!
    >>
    >> thanks!!!
    >>
    >> i'm still unsure why it worked with no spaces but didn't with spaces, but
    >> just replacing "\" with "\\" works and so i'm happy
    >>
    >> thanks again!
    >>
    >>
    >> "Nicholasp27" wrote:
    >>
    >> > thanks for response. i'll try that
    >> > however, why does that make it work when it's c:\testdoc.txt but not c:\test
    >> > doc.txt?
    >> >
    >> > it works if no spaces, doesn't if spaces
    >> >
    >> > also, i am using an html control filebox that allows user to browse to
    >> > file...i was just showing literal string to illustrate here...to me, it seems
    >> > if the browser can find it by browsing, it should work in attaching...but it
    >> > doesn't if space in name, does if no spaces
    >> >
    >> > "Scott Allen" wrote:
    >> >
    >> > > Hi Nicholas:
    >> > >
    >> > > Be careful with escape sequences, which start with a '\'. For
    >> > > instance, "\T" in your code represents a single tab character.
    >> > >
    >> > > You have to either escape the '\' character with another '\', or make
    >> > > the string a verbatim string literal.
    >> > >
    >> > > i.e.
    >> > >
    >> > > "c:\\Test Document.txt"
    >> > >
    >> > > or
    >> > >
    >> > > @"c:\Test Document.txt"
    >> > >
    >> > > HTH,
    >> > >
    >> > > --
    >> > > Scott
    >> > > http://www.OdeToCode.com
    >> > >
    >> > > On Fri, 20 Aug 2004 14:09:02 -0700, "Nicholasp27"
    >> > > <> wrote:
    >> > >
    >> > > >I am trying to have a webform email a user using smtp and be able to attach a
    >> > > >document(s). It works if the document is something like "c:\test.txt" but if
    >> > > >it is "c:\My Documents\user\desktop\test.txt" it gives an error. How do I
    >> > > >fix this?
    >> > > >
    >> > > >Here's code that works if it's c:\testdocument.txt but not if it's c:\test
    >> > > >document.txt
    >> > > >
    >> > > >Dim mailAttachment As Mail.MailAttachment
    >> > > > Try
    >> > > > mailAttachment = New Mail.MailAttachment("c:\Test Document.txt")
    >> > > > email.Attachments.Add(mailAttachment)
    >> > > > System.Web.Mail.SmtpMail.SmtpServer = "smtp.servername.com"
    >> > > > System.Web.Mail.SmtpMail.Send(email)
    >> > > >
    >> > > >Thanks
    >> > >
    >> > >


    --
    Scott
    http://www.OdeToCode.com
     
    Scott Allen, Aug 23, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,092
    Roedy Green
    Jan 24, 2006
  2. B.J.
    Replies:
    4
    Views:
    745
    Toby Inkster
    Apr 23, 2005
  3. Alex Hunsley
    Replies:
    4
    Views:
    3,489
    Tim Williams (gmail)
    Jun 29, 2004
  4. EdWhyatt
    Replies:
    2
    Views:
    425
    Christos Georgiou
    Mar 18, 2006
  5. codewarrior
    Replies:
    0
    Views:
    535
    codewarrior
    May 4, 2009
Loading...

Share This Page