By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,347 Members | 2,113 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,347 IT Pros & Developers. It's quick & easy.

Upload a File to a Web Server and error handling

P: n/a
I need help in implementing proper error handling.

I am trying to upload a file based on the sample code below. The code works
well except if the file selected is too big.

I do know about the maxRequestLength parameter of the <httpRuntime> section
and that works as expected. What I want is to enforce a max file size but
haven't been able to trap the error thrown when the file is too large and
that's where I could use some help.

Thanks
The main code is shown below and was copied from one of MS samples.
<script language="VB" runat="server">
Sub Button1_Click(Source As Object, e As EventArgs)

If Text1.Value = "" Then
Span1.InnerHtml = "Error: you must enter a file name"
Return
End If

If Not (File1.PostedFile Is Nothing) Then
Try
File1.PostedFile.SaveAs(("c:\temp\" & Text1.Value))
Span1.InnerHtml = "File uploaded successfully to <b>c:\temp\" & _
Text1.Value & "</b> on the Web server"
Catch exc As Exception
Span1.InnerHtml = "Error saving file <b>c:\temp\" & _
Text1.Value & "</b><br>" & exc.ToString()
End Try
End If
End Sub 'Button1_Click
</script>

<form enctype="multipart/form-data" runat="server">

Select File to Upload:
<input id="File1"
type="file"
maxlength="30"
runat="server"/>

<p/>
Save as filename (no path):
<input id="Text1"
type="text"
runat="server"/>

<p/>
<span id="Span1"
style="font: 8pt verdana;"
runat="server" />

<p/>
<input type="button"
id="Button1"
value="Upload"
OnServerClick="Button1_Click"
runat="server">

</form>


Nov 18 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Al Smith you can try this -

Dim strFolderDetail As String = "C:\inetpub\wwwroot\MYPROJECTFOLDER\uploads\

'Grab the file name from its fully qualified path at client
Dim strFileName As String = controlName.PostedFile.FileNam

' only the attched file name not its pat
Dim strNewFileName As String = System.IO.Path.GetFileNameWithoutExtension(strFile Name) &
String.Format("{0:MMddyyHHmmss}", Date.Now) &
System.IO.Path.GetExtension(strFileName

'Save uploaded file to server at C:\ServerFolder Tr
controlname.PostedFile.SaveAs(strFolderDetail + strNewFileName
Response.Write("Your File Uploaded Sucessfully at server as: " & strNewFileName

Catch Exp As Exceptio
Response.Write(Exp.Message
End Tr
-------------

in you aspx page you have to pu

<INPUT id="controlName" type="file" size="40" name="controlName" runat="server"
Let me know if you have any problem running this.
Joji
Nov 18 '05 #2

P: n/a
Hi Joji,

My problem is when the byte count of the file exceeds the maxRequestLength
parameter of the <httpRuntime> area of the web.config file and how to trap
that error. So the name of the file is not an issue... at least yet, or did
I miss understand something here.

Thanks
Al

"Joji" <jo********@yahoo.com> wrote in message
news:23**********************************@microsof t.com...
Al Smith you can try this -

Dim strFolderDetail As String = "C:\inetpub\wwwroot\MYPROJECTFOLDER\uploads\"
'Grab the file name from its fully qualified path at client
Dim strFileName As String = controlName.PostedFile.FileName

' only the attched file name not its path
Dim strNewFileName As String = System.IO.Path.GetFileNameWithoutExtension(strFile Name) & _ String.Format("{0:MMddyyHHmmss}", Date.Now) & _ System.IO.Path.GetExtension(strFileName)

'Save uploaded file to server at C:\ServerFolder Try
controlname.PostedFile.SaveAs(strFolderDetail + strNewFileName) Response.Write("Your File Uploaded Sucessfully at server as: " & strNewFileName)
Catch Exp As Exception
Response.Write(Exp.Message)
End Try
--------------

in you aspx page you have to put

<INPUT id="controlName" type="file" size="40" name="controlName" runat="server"> Let me know if you have any problem running this.
Joji

Nov 18 '05 #3

P: n/a
Hi AI,

Thank you for posting in community. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)

Nov 18 '05 #4

P: n/a
I'll check back Steven, thanks.

Al

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:Tj**************@cpmsftngxa07.phx.gbl...
Hi AI,

Thank you for posting in community. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as posible.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)

Nov 18 '05 #5

P: n/a
Hi Al,

We're still looking into your issue. The maximum request length is tested
very early in the processing of an incoming request, well before your page
gets involved. When too large, the request is aborted at this early stage
and the code in your page is not executed. The Try/Catch block around your
call to SaveAs can catch other errors, such as access denied.

We're looking into using an httpModule to handle this error. I'll let you
know as soon as I have more information.

Another possibility is to set maxRequestLength to a high value. Then test
File1.PostedFile.ContentLength before calling File1.PostedFile.SaveAs.
However, this has some drawbacks. One issue is that the large request will
be taking up server memory for a longer time before being discarded. Please
see the "More Information" section in this article for more information
about consequences of setting maxRequestLength to a large value.
323245 HOW TO: Upload a File to a Web Server in ASP.NET by Using Visual
Basic
http://support.microsoft.com/?id=323245

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computerís security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: "Al Smith" <as****@NOSPAMmrisystem.com>
References: <uS**************@TK2MSFTNGP12.phx.gbl> <Tj**************@cpmsftngxa07.phx.gbl> Subject: Re: Upload a File to a Web Server and error handling
Date: Wed, 21 Jan 2004 09:17:37 -0500
Lines: 22
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <ek*************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 12.17.95.135
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP10.
phx.gbl Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:203878
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I'll check back Steven, thanks.

Al

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:Tj**************@cpmsftngxa07.phx.gbl...
Hi AI,

Thank you for posting in community. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as

posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)



Nov 18 '05 #6

P: n/a

Hi Mike,

Thanks for the interim feedback.
We're looking into using an httpModule to handle this error. Sounds very interesting.

Thanks for the link.
I'll be back.

Thanks again,

Al

""Mike Moore [MSFT]"" <mi****@online.microsoft.com> wrote in message
news:DH**************@cpmsftngxa07.phx.gbl... Hi Al,

We're still looking into your issue. The maximum request length is tested
very early in the processing of an incoming request, well before your page
gets involved. When too large, the request is aborted at this early stage
and the code in your page is not executed. The Try/Catch block around your
call to SaveAs can catch other errors, such as access denied.

We're looking into using an httpModule to handle this error. I'll let you
know as soon as I have more information.

Another possibility is to set maxRequestLength to a high value. Then test
File1.PostedFile.ContentLength before calling File1.PostedFile.SaveAs.
However, this has some drawbacks. One issue is that the large request will
be taking up server memory for a longer time before being discarded. Please see the "More Information" section in this article for more information
about consequences of setting maxRequestLength to a large value.
323245 HOW TO: Upload a File to a Web Server in ASP.NET by Using Visual
Basic
http://support.microsoft.com/?id=323245

Thank you, Mike
Microsoft, ASP.NET Support Professional

Nov 18 '05 #7

P: n/a
Hi Al,

This is just a quick note to let you know that we're still researching.
I'll post more as soon as I can.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computerís security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
X-Tomcat-ID: 279843854
References: <uS**************@TK2MSFTNGP12.phx.gbl> <Tj**************@cpmsftngxa07.phx.gbl>
<ek*************@TK2MSFTNGP10.phx.gbl> MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: mi****@online.microsoft.com ("Mike Moore [MSFT]")
Organization: Microsoft
Date: Thu, 22 Jan 2004 23:20:42 GMT
Subject: Re: Upload a File to a Web Server and error handling
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
Message-ID: <DH**************@cpmsftngxa07.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Lines: 71
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:204376
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182

Hi Al,

We're still looking into your issue. The maximum request length is tested
very early in the processing of an incoming request, well before your page gets involved. When too large, the request is aborted at this early stage
and the code in your page is not executed. The Try/Catch block around your call to SaveAs can catch other errors, such as access denied.

We're looking into using an httpModule to handle this error. I'll let you
know as soon as I have more information.

Another possibility is to set maxRequestLength to a high value. Then test
File1.PostedFile.ContentLength before calling File1.PostedFile.SaveAs.
However, this has some drawbacks. One issue is that the large request will be taking up server memory for a longer time before being discarded. Please see the "More Information" section in this article for more information
about consequences of setting maxRequestLength to a large value.
323245 HOW TO: Upload a File to a Web Server in ASP.NET by Using Visual
Basic
http://support.microsoft.com/?id=323245

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward steps listed to improve your computerís security.

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
From: "Al Smith" <as****@NOSPAMmrisystem.com>
References: <uS**************@TK2MSFTNGP12.phx.gbl> <Tj**************@cpmsftngxa07.phx.gbl>
Subject: Re: Upload a File to a Web Server and error handling
Date: Wed, 21 Jan 2004 09:17:37 -0500
Lines: 22
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <ek*************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 12.17.95.135
Path:

cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP10. phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:203878 X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I'll check back Steven, thanks.

Al

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:Tj**************@cpmsftngxa07.phx.gbl...
Hi AI,

Thank you for posting in community. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as

posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS", with no warranties, and confers no rights.)




Nov 18 '05 #8

P: n/a
Hi Mike,

I had no idea that this was a hard one. I just thought I could not find the
proper documentation.

Thanks

Al

""Mike Moore [MSFT]"" <mi****@online.microsoft.com> wrote in message
news:HA*************@cpmsftngxa07.phx.gbl...
Hi Al,

This is just a quick note to let you know that we're still researching.
I'll post more as soon as I can.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
X-Tomcat-ID: 279843854
References: <uS**************@TK2MSFTNGP12.phx.gbl>

<Tj**************@cpmsftngxa07.phx.gbl>
<ek*************@TK2MSFTNGP10.phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: mi****@online.microsoft.com ("Mike Moore [MSFT]")
Organization: Microsoft
Date: Thu, 22 Jan 2004 23:20:42 GMT
Subject: Re: Upload a File to a Web Server and error handling
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
Message-ID: <DH**************@cpmsftngxa07.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Lines: 71
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:204376
NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182

Hi Al,

We're still looking into your issue. The maximum request length is tested very early in the processing of an incoming request, well before your

page
gets involved. When too large, the request is aborted at this early stage and the code in your page is not executed. The Try/Catch block around

your
call to SaveAs can catch other errors, such as access denied.

We're looking into using an httpModule to handle this error. I'll let you know as soon as I have more information.

Another possibility is to set maxRequestLength to a high value. Then test File1.PostedFile.ContentLength before calling File1.PostedFile.SaveAs.
However, this has some drawbacks. One issue is that the large request

will
be taking up server memory for a longer time before being discarded.

Please
see the "More Information" section in this article for more information
about consequences of setting maxRequestLength to a large value.
323245 HOW TO: Upload a File to a Web Server in ASP.NET by Using Visual
Basic
http://support.microsoft.com/?id=323245

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three

straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no

rights.


--------------------
From: "Al Smith" <as****@NOSPAMmrisystem.com>
References: <uS**************@TK2MSFTNGP12.phx.gbl>

<Tj**************@cpmsftngxa07.phx.gbl>
Subject: Re: Upload a File to a Web Server and error handling
Date: Wed, 21 Jan 2004 09:17:37 -0500
Lines: 22
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <ek*************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 12.17.95.135
Path:

cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP10.
phx.gbl
Xref: cpmsftngxa07.phx.gbl

microsoft.public.dotnet.framework.aspnet:203878 X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I'll check back Steven, thanks.

Al

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:Tj**************@cpmsftngxa07.phx.gbl...
> Hi AI,
>
> Thank you for posting in community. Regarding on the issue, I am
> finding proper resource to assist you and we will update as soon as
posible.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security(This posting is provided "AS IS", > with no warranties, and confers no rights.)
>


Nov 18 '05 #9

P: n/a
Hello
It looks like framework may handle the maxRequestLength and not allow you
to handle error unless you want to set the size to be very large and then
you can handle checking the size of the request in your code and send back
error. I will do some checking to see if there is any way we can trap the
return data and modify it in managed code. However if framework handles
this without going through pipline then your only options will be to set it
to a large size and do your own checking or create ISAPI filter.

Thanks
Brian [MS]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Al Smith" <as****@NOSPAMmrisystem.com>
| References: <uS**************@TK2MSFTNGP12.phx.gbl>
<23**********************************@microsoft.co m>
| Subject: Re: Upload a File to a Web Server and error handling
| Date: Tue, 20 Jan 2004 17:41:00 -0500
| Lines: 50
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <e7**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.17.95.135
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!tk2msftngp13.
phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:203673
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Joji,
|
| My problem is when the byte count of the file exceeds the maxRequestLength
| parameter of the <httpRuntime> area of the web.config file and how to trap
| that error. So the name of the file is not an issue... at least yet, or
did
| I miss understand something here.
|
| Thanks
| Al
|
|
|
| "Joji" <jo********@yahoo.com> wrote in message
| news:23**********************************@microsof t.com...
| > Al Smith you can try this -
| >
| > Dim strFolderDetail As String =
| "C:\inetpub\wwwroot\MYPROJECTFOLDER\uploads\"
| >
| > 'Grab the file name from its fully qualified path at client
| > Dim strFileName As String = controlName.PostedFile.FileName
| >
| > ' only the attched file name not its path
| > Dim strNewFileName As String =
| System.IO.Path.GetFileNameWithoutExtension(strFile Name) & _
| >
| String.Format("{0:MMddyyHHmmss}", Date.Now) & _
| >
| System.IO.Path.GetExtension(strFileName)
| >
| >
| > 'Save uploaded file to server at C:\ServerFolder Try
| > controlname.PostedFile.SaveAs(strFolderDetail +
| strNewFileName)
| > Response.Write("Your File Uploaded Sucessfully at server
as: "
| & strNewFileName)
| >
| > Catch Exp As Exception
| > Response.Write(Exp.Message)
| > End Try
| > --------------
| >
| > in you aspx page you have to put
| >
| > <INPUT id="controlName" type="file" size="40" name="controlName"
| runat="server">
| > Let me know if you have any problem running this.
| > Joji
|
|
|

Nov 18 '05 #10

P: n/a
Thanks Brian,

I am beginning to think ISAPI is the only solution. Thanks and I;ll check
back.

Al

"Brian Combs" <Br***@online.microsoft.com> wrote in message
news:m7**************@cpmsftngxa07.phx.gbl...
Hello
It looks like framework may handle the maxRequestLength and not allow you
to handle error unless you want to set the size to be very large and then
you can handle checking the size of the request in your code and send back
error. I will do some checking to see if there is any way we can trap the
return data and modify it in managed code. However if framework handles
this without going through pipline then your only options will be to set it to a large size and do your own checking or create ISAPI filter.

Thanks
Brian [MS]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights. --------------------
| From: "Al Smith" <as****@NOSPAMmrisystem.com>
| References: <uS**************@TK2MSFTNGP12.phx.gbl>
<23**********************************@microsoft.co m>
| Subject: Re: Upload a File to a Web Server and error handling
| Date: Tue, 20 Jan 2004 17:41:00 -0500
| Lines: 50
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <e7**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.17.95.135
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!tk2msftngp13. phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:203673 | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi Joji,
|
| My problem is when the byte count of the file exceeds the maxRequestLength | parameter of the <httpRuntime> area of the web.config file and how to trap | that error. So the name of the file is not an issue... at least yet, or
did
| I miss understand something here.
|
| Thanks
| Al
|
|
|
| "Joji" <jo********@yahoo.com> wrote in message
| news:23**********************************@microsof t.com...
| > Al Smith you can try this -
| >
| > Dim strFolderDetail As String =
| "C:\inetpub\wwwroot\MYPROJECTFOLDER\uploads\"
| >
| > 'Grab the file name from its fully qualified path at client
| > Dim strFileName As String = controlName.PostedFile.FileName
| >
| > ' only the attched file name not its path
| > Dim strNewFileName As String =
| System.IO.Path.GetFileNameWithoutExtension(strFile Name) & _
| >
| String.Format("{0:MMddyyHHmmss}", Date.Now) & _
| >
| System.IO.Path.GetExtension(strFileName)
| >
| >
| > 'Save uploaded file to server at C:\ServerFolder Try
| > controlname.PostedFile.SaveAs(strFolderDetail +
| strNewFileName)
| > Response.Write("Your File Uploaded Sucessfully at server
as: "
| & strNewFileName)
| >
| > Catch Exp As Exception
| > Response.Write(Exp.Message)
| > End Try
| > --------------
| >
| > in you aspx page you have to put
| >
| > <INPUT id="controlName" type="file" size="40" name="controlName"
| runat="server">
| > Let me know if you have any problem running this.
| > Joji
|
|
|

Nov 18 '05 #11

P: n/a
Hello
You should be able to trap the error in the Application_Error event handler
in the global.asax file and then redirect the reqeust to your own custom
error page. Take a look at the following article for how to create custom
error reporting pages.
306355 HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using
Visual
http://support.microsoft.com/?id=306355

This would be better then trying to do this in an HttpModule.

Thanks
Brian [MS]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Al Smith" <as****@NOSPAMmrisystem.com>
| References: <uS**************@TK2MSFTNGP12.phx.gbl>
<23**********************************@microsoft.co m>
<e7**************@tk2msftngp13.phx.gbl>
<m7**************@cpmsftngxa07.phx.gbl>
| Subject: Re: Upload a File to a Web Server and error handling
| Date: Thu, 29 Jan 2004 22:01:42 -0500
| Lines: 104
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <uF**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.17.95.135
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:206313
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks Brian,
|
| I am beginning to think ISAPI is the only solution. Thanks and I;ll check
| back.
|
| Al
|
| "Brian Combs" <Br***@online.microsoft.com> wrote in message
| news:m7**************@cpmsftngxa07.phx.gbl...
| > Hello
| > It looks like framework may handle the maxRequestLength and not allow
you
| > to handle error unless you want to set the size to be very large and
then
| > you can handle checking the size of the request in your code and send
back
| > error. I will do some checking to see if there is any way we can trap
the
| > return data and modify it in managed code. However if framework handles
| > this without going through pipline then your only options will be to set
| it
| > to a large size and do your own checking or create ISAPI filter.
| >
| > Thanks
| > Brian [MS]
| > Microsoft Developer Support
| > This posting is provided "AS IS" with no warranties, and confers no
| rights.
| > --------------------
| > | From: "Al Smith" <as****@NOSPAMmrisystem.com>
| > | References: <uS**************@TK2MSFTNGP12.phx.gbl>
| > <23**********************************@microsoft.co m>
| > | Subject: Re: Upload a File to a Web Server and error handling
| > | Date: Tue, 20 Jan 2004 17:41:00 -0500
| > | Lines: 50
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| > | Message-ID: <e7**************@tk2msftngp13.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: 12.17.95.135
| > | Path:
| >
|
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!tk2msftngp13.
| > phx.gbl
| > | Xref: cpmsftngxa07.phx.gbl
| microsoft.public.dotnet.framework.aspnet:203673
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Hi Joji,
| > |
| > | My problem is when the byte count of the file exceeds the
| maxRequestLength
| > | parameter of the <httpRuntime> area of the web.config file and how to
| trap
| > | that error. So the name of the file is not an issue... at least yet,
or
| > did
| > | I miss understand something here.
| > |
| > | Thanks
| > | Al
| > |
| > |
| > |
| > | "Joji" <jo********@yahoo.com> wrote in message
| > | news:23**********************************@microsof t.com...
| > | > Al Smith you can try this -
| > | >
| > | > Dim strFolderDetail As String =
| > | "C:\inetpub\wwwroot\MYPROJECTFOLDER\uploads\"
| > | >
| > | > 'Grab the file name from its fully qualified path at client
| > | > Dim strFileName As String = controlName.PostedFile.FileName
| > | >
| > | > ' only the attched file name not its path
| > | > Dim strNewFileName As String =
| > | System.IO.Path.GetFileNameWithoutExtension(strFile Name) & _
| > | >
| > | String.Format("{0:MMddyyHHmmss}", Date.Now) & _
| > | >
| > | System.IO.Path.GetExtension(strFileName)
| > | >
| > | >
| > | > 'Save uploaded file to server at C:\ServerFolder Try
| > | > controlname.PostedFile.SaveAs(strFolderDetail +
| > | strNewFileName)
| > | > Response.Write("Your File Uploaded Sucessfully at server
| > as: "
| > | & strNewFileName)
| > | >
| > | > Catch Exp As Exception
| > | > Response.Write(Exp.Message)
| > | > End Try
| > | > --------------
| > | >
| > | > in you aspx page you have to put
| > | >
| > | > <INPUT id="controlName" type="file" size="40" name="controlName"
| > | runat="server">
| > | > Let me know if you have any problem running this.
| > | > Joji
| > |
| > |
| > |
| >
|
|
|

Nov 18 '05 #12

P: n/a
Thanks Brian,

I'll give that a try.

Al
"Brian Combs" <Br***@online.microsoft.com> wrote in message
news:KJ**************@cpmsftngxa07.phx.gbl...
Hello
You should be able to trap the error in the Application_Error event handler in the global.asax file and then redirect the reqeust to your own custom
error page. Take a look at the following article for how to create custom
error reporting pages.
306355 HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using
Visual
http://support.microsoft.com/?id=306355

This would be better then trying to do this in an HttpModule.

Thanks
Brian [MS]
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights. --------------------
| From: "Al Smith" <as****@NOSPAMmrisystem.com>
| References: <uS**************@TK2MSFTNGP12.phx.gbl>
<23**********************************@microsoft.co m>
<e7**************@tk2msftngp13.phx.gbl>
<m7**************@cpmsftngxa07.phx.gbl>
| Subject: Re: Upload a File to a Web Server and error handling
| Date: Thu, 29 Jan 2004 22:01:42 -0500
| Lines: 104
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| Message-ID: <uF**************@TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 12.17.95.135
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08 phx.gbl!TK2MSFTNGP12.phx.gbl
| Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:206313 | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks Brian,
|
| I am beginning to think ISAPI is the only solution. Thanks and I;ll check | back.
|
| Al
|
| "Brian Combs" <Br***@online.microsoft.com> wrote in message
| news:m7**************@cpmsftngxa07.phx.gbl...
| > Hello
| > It looks like framework may handle the maxRequestLength and not allow
you
| > to handle error unless you want to set the size to be very large and
then
| > you can handle checking the size of the request in your code and send
back
| > error. I will do some checking to see if there is any way we can trap
the
| > return data and modify it in managed code. However if framework handles | > this without going through pipline then your only options will be to set | it
| > to a large size and do your own checking or create ISAPI filter.
| >
| > Thanks
| > Brian [MS]
| > Microsoft Developer Support
| > This posting is provided "AS IS" with no warranties, and confers no
| rights.
| > --------------------
| > | From: "Al Smith" <as****@NOSPAMmrisystem.com>
| > | References: <uS**************@TK2MSFTNGP12.phx.gbl>
| > <23**********************************@microsoft.co m>
| > | Subject: Re: Upload a File to a Web Server and error handling
| > | Date: Tue, 20 Jan 2004 17:41:00 -0500
| > | Lines: 50
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
| > | Message-ID: <e7**************@tk2msftngp13.phx.gbl>
| > | Newsgroups: microsoft.public.dotnet.framework.aspnet
| > | NNTP-Posting-Host: 12.17.95.135
| > | Path:
| >
|
cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!tk2msftngp13. | > phx.gbl
| > | Xref: cpmsftngxa07.phx.gbl
| microsoft.public.dotnet.framework.aspnet:203673
| > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| > |
| > | Hi Joji,
| > |
| > | My problem is when the byte count of the file exceeds the
| maxRequestLength
| > | parameter of the <httpRuntime> area of the web.config file and how to | trap
| > | that error. So the name of the file is not an issue... at least yet, or
| > did
| > | I miss understand something here.
| > |
| > | Thanks
| > | Al
| > |
| > |
| > |
| > | "Joji" <jo********@yahoo.com> wrote in message
| > | news:23**********************************@microsof t.com...
| > | > Al Smith you can try this -
| > | >
| > | > Dim strFolderDetail As String =
| > | "C:\inetpub\wwwroot\MYPROJECTFOLDER\uploads\"
| > | >
| > | > 'Grab the file name from its fully qualified path at client | > | > Dim strFileName As String = controlName.PostedFile.FileName | > | >
| > | > ' only the attched file name not its path
| > | > Dim strNewFileName As String =
| > | System.IO.Path.GetFileNameWithoutExtension(strFile Name) & _
| > | >
| > | String.Format("{0:MMddyyHHmmss}", Date.Now) & _
| > | >
| > | System.IO.Path.GetExtension(strFileName)
| > | >
| > | >
| > | > 'Save uploaded file to server at C:\ServerFolder Try | > | > controlname.PostedFile.SaveAs(strFolderDetail +
| > | strNewFileName)
| > | > Response.Write("Your File Uploaded Sucessfully at server | > as: "
| > | & strNewFileName)
| > | >
| > | > Catch Exp As Exception
| > | > Response.Write(Exp.Message)
| > | > End Try
| > | > --------------
| > | >
| > | > in you aspx page you have to put
| > | >
| > | > <INPUT id="controlName" type="file" size="40" name="controlName"
| > | runat="server">
| > | > Let me know if you have any problem running this.
| > | > Joji
| > |
| > |
| > |
| >
|
|
|

Nov 18 '05 #13

P: n/a
Hi Al,

I found some more information for you. Sorry it took so long.

Most of the processing done by ASP.NET does not begin until after the
server has received the whole post from the client. When ASP.NET detects up
front that the post is too large, then it immediately sends an error,
without proceeding any further. While this has some benefits, it also means
that you cannot trap this error to handle it in a custom manner.

One benefit is that your server does not have to receive and store in
memory the entire posted data before rejecting it. This saves server
resources.

Another benefit is that the client may receive this error before it
finishes sending everything it wants to send. If it receives this
particular error (rather than a custom page of your choice), the client can
recognize this error as a signal to stop sending even though it's not
finished.

I'm sorry this isn't the answer you were hoping for, but I hope the
information is helpful.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computerís security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: "Al Smith" <as****@NOSPAMmrisystem.com>
References: <uS**************@TK2MSFTNGP12.phx.gbl> <Tj**************@cpmsftngxa07.phx.gbl>
<ek*************@TK2MSFTNGP10.phx.gbl>
<DH**************@cpmsftngxa07.phx.gbl>
<HA*************@cpmsftngxa07.phx.gbl> Subject: Re: Upload a File to a Web Server and error handling
Date: Tue, 27 Jan 2004 16:39:15 -0500
Lines: 142
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Message-ID: <#I**************@TK2MSFTNGP09.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 12.17.95.135
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP09.
phx.gbl Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:205510
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Hi Mike,

I had no idea that this was a hard one. I just thought I could not find the proper documentation.

Thanks

Al

""Mike Moore [MSFT]"" <mi****@online.microsoft.com> wrote in message
news:HA*************@cpmsftngxa07.phx.gbl...
Hi Al,

This is just a quick note to let you know that we're still researching.
I'll post more as soon as I can.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three

straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no

rights.


--------------------
X-Tomcat-ID: 279843854
References: <uS**************@TK2MSFTNGP12.phx.gbl>

<Tj**************@cpmsftngxa07.phx.gbl>
<ek*************@TK2MSFTNGP10.phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: mi****@online.microsoft.com ("Mike Moore [MSFT]")
Organization: Microsoft
Date: Thu, 22 Jan 2004 23:20:42 GMT
Subject: Re: Upload a File to a Web Server and error handling
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
Message-ID: <DH**************@cpmsftngxa07.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Lines: 71
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:204376 NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182

Hi Al,

We're still looking into your issue. The maximum request length is tested very early in the processing of an incoming request, well before your

page
gets involved. When too large, the request is aborted at this early stage and the code in your page is not executed. The Try/Catch block around

your
call to SaveAs can catch other errors, such as access denied.

We're looking into using an httpModule to handle this error. I'll let you know as soon as I have more information.

Another possibility is to set maxRequestLength to a high value. Then test File1.PostedFile.ContentLength before calling File1.PostedFile.SaveAs.
However, this has some drawbacks. One issue is that the large request

will
be taking up server memory for a longer time before being discarded.

Please
see the "More Information" section in this article for more information about consequences of setting maxRequestLength to a large value.
323245 HOW TO: Upload a File to a Web Server in ASP.NET by Using Visual Basic
http://support.microsoft.com/?id=323245

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the http://www.microsoft.com/protect site and perform the three

straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no

rights.


--------------------
> From: "Al Smith" <as****@NOSPAMmrisystem.com>
> References: <uS**************@TK2MSFTNGP12.phx.gbl>
<Tj**************@cpmsftngxa07.phx.gbl>
> Subject: Re: Upload a File to a Web Server and error handling
> Date: Wed, 21 Jan 2004 09:17:37 -0500
> Lines: 22
> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
> Message-ID: <ek*************@TK2MSFTNGP10.phx.gbl>
> Newsgroups: microsoft.public.dotnet.framework.aspnet
> NNTP-Posting-Host: 12.17.95.135
> Path:

cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTN GP08.phx.gbl!TK2MSFTNGP10.
phx.gbl
> Xref: cpmsftngxa07.phx.gbl

microsoft.public.dotnet.framework.aspnet:203878
> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
>
> I'll check back Steven, thanks.
>
> Al
>
> "Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message > news:Tj**************@cpmsftngxa07.phx.gbl...
> > Hi AI,
> >
> > Thank you for posting in community. Regarding on the issue, I am
> > finding proper resource to assist you and we will update as soon as > posible.
> >
> > Regards,
> >
> > Steven Cheng
> > Microsoft Online Support
> >
> > Get Secure! www.microsoft.com/security(This posting is provided
"AS IS",
> > with no warranties, and confers no rights.)
> >
>
>
>



Nov 18 '05 #14

P: n/a
Thanks for your assistance Mike.

Al
""Mike Moore [MSFT]"" <mi****@online.microsoft.com> wrote in message
news:xh**************@cpmsftngxa07.phx.gbl...
Hi Al,

I found some more information for you. Sorry it took so long.

Most of the processing done by ASP.NET does not begin until after the
server has received the whole post from the client. When ASP.NET detects up front that the post is too large, then it immediately sends an error,
without proceeding any further. While this has some benefits, it also means that you cannot trap this error to handle it in a custom manner.

One benefit is that your server does not have to receive and store in
memory the entire posted data before rejecting it. This saves server
resources.

Another benefit is that the client may receive this error before it
finishes sending everything it wants to send. If it receives this
particular error (rather than a custom page of your choice), the client can recognize this error as a signal to stop sending even though it's not
finished.

I'm sorry this isn't the answer you were hoping for, but I hope the
information is helpful.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.

Nov 18 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.