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
@dotnet.itags.org."c:\Test Document.txt"
HTH,
--
Scott
http://www.OdeToCode.com
On Fri, 20 Aug 2004 14:09:02 -0700, "Nicholasp27"
<Nicholasp27@dotnet.itags.org.discussions.microsoft.com> 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)
>Thanksthanks 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"
> <Nicholasp27@.discussions.microsoft.com> 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
>
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"
> > <Nicholasp27@.discussions.microsoft.com> 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
I'm glad you figured it out!
--
Scott
On Mon, 23 Aug 2004 07:09:02 -0700, "Nicholasp27"
<Nicholasp27@.discussions.microsoft.com> 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"
>> > > <Nicholasp27@.discussions.microsoft.com> 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
0 comments:
Post a Comment