472,334 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

Upload a File to a Web Server and error handling

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
14 3752
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
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
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
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
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

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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be...
6
by: Thomas Due | last post by:
Hi, I am writing an ASP.NET project where I allow users to upload files to the server. I have changed to web.config to allow a total file size of...
4
by: Pavils Jurjans | last post by:
Hello, I have the following setup: The page that contains the form with file upolad HTML control resides on another server that doesn't have...
3
by: J055 | last post by:
Hi How do I tell the user he has tried to upload a file which is too big... 1. when the httpRuntime.maxRequestLength has been exceeded and 2....
6
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
I have a strange problem when uploading a PDF document to a web-server. When I try this to a web-server running Apache 2 on a FC 4, it fails....
8
by: Newcomsas | last post by:
Hello. I'm experiecing a problem with file uploads from ASP pages. On a Windows 2000 - IIS 5 server we're running an ASP Classic application...
2
by: G | last post by:
Hello Friend, I am handling a module using ASP3.0 which has to upload an movie clipsof size 1 mb or 2 mb. i have a code which upload only files...
0
by: poojamangal | last post by:
I want to upload images or pdf files. but i m unable to do so. i got error. please help me to sort it out.. my code is: <% 'on error resume...
5
by: kailashchandra | last post by:
I am trying to upload a file in php,but it gives me error msg please Help me? My Code is like below:- i have one php file named upload.php and i...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.