|
 |
aspx thread: Problem with uploaded files
Message #1 by "Hugh McLaughlin" <hugh@k...> on Mon, 15 Apr 2002 11:43:16
|
|
Hello Everyone and thanks for your help in advance. I am writing an
ASP.Net page that
allows users to type in an email and attach a file to send to the
recipient. However, I
want to give the user the option of not having to attach a file. I
created a form that
allows for browing of the client machine. The page then uses
FileAttached.FilePosted with
FileAttached being the name of the input form for browsing, to upload the
file to the server,
then attach it as an email. Where I am having problems
is that when the user does not attach a file, the application fails.
However, I think
I have set up the condtional statement correctly. Here is the code block:
If Not IsNothing( FileAttached.PostedFile ) Then
'Write the uploaded file to disk
Dim strFileName AS String = Path.GetFileName
(FileAttached.PostedFile.FileName)
Dim strFilePath AS String = ConfigurationSettings.AppSettings
("UploadPath")
FileAttached.PostedFile.SaveAs(strFilePath & strFileName)
'Attach the file to the email
Dim MyAttachment As MailAttachment
'Code fails at this line if not attached
MyAttachment = New MailAttachment(strFilePath & strFileName)
myMessage.Attachments.Add(MyAttachment)
End If
I can't understand how it even gets to this line if there is no file
attached. Any help
would be greatly apprecited. Thanks.
Message #2 by "Scott Guthrie" <scottgu@m...> on Mon, 15 Apr 2002 08:10:10 -0700
|
|
Hi Hugh,
Try changing your If Not statement to also make sure that
FileAttached.PostedFile.ContentLength > 0. I think this is probably the
best way to detect if anything has been uploaded.
Thanks,
Scott
-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...]
Sent: Monday, April 15, 2002 4:43 AM
To: ASP+
Subject: [aspx] Problem with uploaded files
Hello Everyone and thanks for your help in advance. I am writing an
ASP.Net page that
allows users to type in an email and attach a file to send to the
recipient. However, I
want to give the user the option of not having to attach a file. I
created a form that
allows for browing of the client machine. The page then uses
FileAttached.FilePosted with
FileAttached being the name of the input form for browsing, to upload
the
file to the server,
then attach it as an email. Where I am having problems
is that when the user does not attach a file, the application fails.
However, I think
I have set up the condtional statement correctly. Here is the code
block:
If Not IsNothing( FileAttached.PostedFile ) Then
'Write the uploaded file to disk
Dim strFileName AS String =3D Path.GetFileName
(FileAttached.PostedFile.FileName)
Dim strFilePath AS String =3D ConfigurationSettings.AppSettings
("UploadPath")
FileAttached.PostedFile.SaveAs(strFilePath & strFileName)
'Attach the file to the email
Dim MyAttachment As MailAttachment
'Code fails at this line if not attached
MyAttachment =3D New MailAttachment(strFilePath & strFileName)
myMessage.Attachments.Add(MyAttachment)
End If
I can't understand how it even gets to this line if there is no file
attached. Any help
would be greatly apprecited. Thanks.
Message #3 by "Hugh McLaughlin" <hugh@k...> on Tue, 16 Apr 2002 00:25:37
|
|
Thanks Scott. this worked like a charm, but could you help me understand
why?
Hugh
> Hi Hugh,
Try changing your If Not statement to also make sure that
FileAttached.PostedFile.ContentLength > 0. I think this is probably the
best way to detect if anything has been uploaded.
Thanks,
Scott
-----Original Message-----
From: Hugh McLaughlin [mailto:hugh@k...]
Sent: Monday, April 15, 2002 4:43 AM
To: ASP+
Subject: [aspx] Problem with uploaded files
Hello Everyone and thanks for your help in advance. I am writing an
ASP.Net page that
allows users to type in an email and attach a file to send to the
recipient. However, I
want to give the user the option of not having to attach a file. I
created a form that
allows for browing of the client machine. The page then uses
FileAttached.FilePosted with
FileAttached being the name of the input form for browsing, to upload
the
file to the server,
then attach it as an email. Where I am having problems
is that when the user does not attach a file, the application fails.
However, I think
I have set up the condtional statement correctly. Here is the code
block:
If Not IsNothing( FileAttached.PostedFile ) Then
'Write the uploaded file to disk
Dim strFileName AS String =3D Path.GetFileName
(FileAttached.PostedFile.FileName)
Dim strFilePath AS String =3D ConfigurationSettings.AppSettings
("UploadPath")
FileAttached.PostedFile.SaveAs(strFilePath & strFileName)
'Attach the file to the email
Dim MyAttachment As MailAttachment
'Code fails at this line if not attached
MyAttachment =3D New MailAttachment(strFilePath & strFileName)
myMessage.Attachments.Add(MyAttachment)
End If
I can't understand how it even gets to this line if there is no file
attached. Any help
would be greatly apprecited. Thanks.
|
|
 |