This is a migrated thread and some comments may be shown as answers.

[Solved] Error when uploading file larger than allowed

10 Answers 271 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 20 Apr 2009, 06:45 PM
When I try to upload a file larger than the MaxFileSize I get a .net error page with "Value does not fall within the expected range."  I don't want the user to get this.  I want the user to get a message on the upload screen.  How do I test for this before it throws the error?

10 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 21 Apr 2009, 08:57 AM
Hello John,

RadUpload does not throw an error when the uploaded file size is more than MaxFileSize. Instead it moves the latter file to the InvalidFiles collection. Are you sure that you are using RadUpload for ASP.NET AJAX? If so, please send us a sample project thus we can investigate the issue.

Sincerely yours,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
John
Top achievements
Rank 1
answered on 21 Apr 2009, 12:01 PM
.aspx page

<

 

telerik:RadUpload ID="FUFieldPrintOut" runat="server" FocusOnLoad="true" AllowedFileExtensions=".pdf"  />

 

 

<telerik:RadProgressArea id="RadProgressArea1" runat="server"  >

 

 

<Localization Uploaded="Uploaded" ></Localization>

 

 

</telerik:RadProgressArea>

 

 

<telerik:RadProgressManager id="RadProgressManager1" runat="server" RegisterForSubmit="False" />

 

 

</td>

 

 

</tr>

 

 

<tr>

 

 

<td>

 

 

<asp:Button runat="server" ID="btnFieldPrintOut" Text="Upload" /><asp:CustomValidator runat="server" ID="cvFU" Display="Dynamic" ClientValidationFunction="validateRadUpload1" ErrorMessage="Invalid File Extention" />

 

 

 

 

</td>

 

 

</tr>

 

 

</

 

table>

 

 

<script type="text/javascript">

 

 

function validateRadUpload1(source, arguments)

 

{

arguments.IsValid = getRadUpload(

'<%= FUFieldPrintout.ClientID %>').validateExtensions();

 

}

 

</script>

.aspx.vb Page

 

 

Protected Sub btnFieldPrintOut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFieldPrintOut.Click

 

 

 

 

If FUFieldPrintOut.UploadedFiles.Count > 0 Then

 

 

 

 

 

For Each validFile As UploadedFile In FUFieldPrintOut.UploadedFiles

 

 

Dim Name As String = FileNameWithoutExtension(validFile.FileName.ToString)

 

 

Dim len As Integer = validFile.ContentLength

 

 

Dim pic() As Byte = New Byte(len) {}

 

validFile.InputStream.Read(pic, 0, len)

 

Using cmd As New SqlCommand("UploadFieldPrintout", myConnection)

 

cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.AddWithValue(

"@File", pic)

 

cmd.Parameters.AddWithValue(

"@Name", Name)

 

myConnection.Open()

cmd.ExecuteNonQuery()

myConnection.Close()

 

End Using

 

 

 

 

 

Next

 

 

 

 

 

End If

End Sub

 

0
John
Top achievements
Rank 1
answered on 21 Apr 2009, 01:00 PM
I have been trying different variations of validating the files and it appears that I only get the error with one specific file on my system.  The PDF works normally so I am not sure what the difference is other than that it 50MB larger than then my maxfilesize.
0
Genady Sergeev
Telerik team
answered on 23 Apr 2009, 09:50 AM
Hello John,

I have reviewed your code and I did not manage to find any broken parts. I suppose that for some reason the code for inserting into DB fails because the RadUpload does not throw such an error. I suggest you to wrap your database inserting code into a Try/Catch statement and observe whether the error persist. If you remove the MaxFileSize property does the failing PDF file fail again?

Best wishes,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
John
Top achievements
Rank 1
answered on 23 Apr 2009, 12:24 PM
I have tried that and I still get the same error.  The error only occurs when I try to upload a specific file (just happens to be the Telerik manual).  I am able to open the file and it opens fine.
0
Genady Sergeev
Telerik team
answered on 27 Apr 2009, 07:58 AM
Hello John,

It seems that your code for insertion in the database is throwing the error. I suggest you to change it. I have tried uploading the Telerik Manual ( RadControl.pdf size 50.8 mb ) when MaxFileSize was set to "20000" and there were no errors, the file was moved to the invalid files collection instead. I have also tried your code, everything is correct since I do not have the database and the stored procedures that you are using. I suggest you to debug your code and tell us where exactly the error is thrown. It will help a lot to understand the error.

Best wishes,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
John
Top achievements
Rank 1
answered on 27 Apr 2009, 12:58 PM

Database:

USE

 

[Database]

 

GO

 

/****** Object: Table [dbo].[FieldPrintouts] Script Date: 04/27/2009 08:26:12 ******/

SET

 

ANSI_NULLS ON

 

 

GO

SET

 

QUOTED_IDENTIFIER ON

 

 

GO

SET

 

ANSI_PADDING ON

 

 

GO

CREATE

 

TABLE [dbo].[FieldPrintouts](

 

 

[FieldPrintoutID] [int]

IDENTITY(1,1) NOT NULL,

 

 

[FieldPrintoutName] [nvarchar]

(max) NOT NULL,

 

 

[FieldPrintoutFile] [varbinary]

(max) NOT NULL

 

)

 

 

ON [PRIMARY]

 

GO

 

SET

 

ANSI_PADDING OFF

Stored Procedure:

 

USE

 

[Database]

 

GO

 

 

 

/****** Object: StoredProcedure [dbo].[UploadFieldPrintout] Script Date: 04/27/2009 08:27:55 ******/

 

 

 

 

SET

 

 

ANSI_NULLS ON

 

 

 

 

 

GO

 

 

 

SET

 

 

QUOTED_IDENTIFIER ON

 

 

 

 

 

GO

 

 

 

-- =============================================

-- Author: <Author,,Name>

-- Create date: <Create Date,,>

-- Description: <Description,,>

-- =============================================

 

 

 

 

ALTER

 

 

PROCEDURE [dbo].[UploadFieldPrintout]

 

@File

 

VARBINARY(MAX),

 

 

 

 

 

@Name

 

NVARCHAR(MAX)

 

 

 

 

 

AS

BEGIN

 

 

 

 

 

 

INSERT INTO FieldPrintouts (FieldPrintoutFile, FieldPrintoutName) VALUES (@File, @Name)

 

 

 

 

 

END

.aspx :

 

 

 

<tr>

 

 

 

 

<td>

 

 

 

 

Upload Field Printout here:<asp:Label CssClass="bodytext_small" ID="rsuccess" runat="server" Visible="false" />

 

 

 

 

</td>

 

 

 

 

</tr>

 

 

 

 

<tr>

 

 

 

 

<td>

 

 

 

 

<telerik:RadUpload ID="FUFieldPrintOut" runat="server" FocusOnLoad="true" AllowedFileExtensions=".pdf" Skin="Default" EnableEmbeddedSkins="false" MaxFileSize="200000" />

 

 

 

 

<telerik:RadProgressArea id="RadProgressArea1" runat="server" Skin="Default" EnableEmbeddedSkins="false" >

 

 

 

 

<Localization Uploaded="Uploaded" ></Localization>

 

 

 

 

</telerik:RadProgressArea>

 

 

 

 

<telerik:RadProgressManager id="RadProgressManager1" runat="server" Skin="Default" EnableEmbeddedSkins="false" RegisterForSubmit="False" />

 

 

 

</td>

 

 

 

 

</tr>

 

 

 

 

<tr>

 

 

 

 

<td>

 

 

 

 

<asp:Button runat="server" ID="btnFieldPrintOut" Text="Upload" /><asp:CustomValidator runat="server" ID="cvFU" Display="Dynamic" ErrorMessage="Invalid File" />

 

 

 

 

</td>

 

 

 

 

</tr>

aspx.vb:

 

Protected

 

Sub btnFieldPrintOut_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFieldPrintOut.Click

 

rsuccess.Visible =

 

False

 

 

 

 

 

 

 

 

If FUFieldPrintOut.UploadedFiles.Count > 0 Then

 

 

 

 

 

 

 

 

For Each validFile As UploadedFile In FUFieldPrintOut.UploadedFiles

 

 

 

Dim Name As String = Path.GetFileNameWithoutExtension(validFile.FileName.ToString)

 

 

 

Dim len As Integer = validFile.ContentLength

 

 

 

Dim pic() As Byte = New Byte(len) {}

 

validFile.InputStream.Read(pic, 0, len)

 

 

Using cmd As New SqlCommand("UploadFieldPrintout", myConnection)

 

cmd.CommandType = CommandType.StoredProcedure

cmd.Parameters.AddWithValue(

 

"@File", pic)

 

cmd.Parameters.AddWithValue(

 

"@Name", Name)

 

myConnection.Open()

cmd.ExecuteNonQuery()

myConnection.Close()

 

 

End Using

 

 

 

 

 

 

 

 

Next

 

 

 

 

 

 

 

 

End If

 

 

 

 

 

 

rsuccess.ForeColor = Drawing.Color.Green

rsuccess.Visible =

 

True

 

 

 

 

 

 

Load_List()

 

 

End Sub

 

 

 

 

Error :
 

Server Error in '/' Application.

Value does not fall within the expected range.

 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Value does not fall within the expected range.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentException: Value does not fall within the expected range.]
   System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0
   System.Web.Util.Misc.ThrowIfFailedHr(Int32 hresult) +11079333
   System.Web.Hosting.IIS7WorkerRequest.GetQueryStringRawBytes() +59
   System.Web.HttpRequest.get_QueryStringBytes() +62
   System.Web.HttpRequest.FillInQueryStringCollection() +19
   System.Web.HttpRequest.get_QueryString() +119
   Telerik.Web.UI.RadUploadContext.GetUploadUniqueIdentifier(HttpContext context) +23
   Telerik.Web.UI.RadUploadHttpModule.app_EndRequest(Object sender, EventArgs e) +167
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171

 


Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074

 

 

 

 

0
John
Top achievements
Rank 1
answered on 27 Apr 2009, 02:00 PM
I have figured out that if the file is converted to an image format pdf then it works fine.  I have other pdfs that are created in Adobe that seem to upload fine but when they are retreived I get an error stating "There was an error opening this document,  The file is damaged and could not be repaired.".  Any ideas on why this would happen?
0
John
Top achievements
Rank 1
answered on 27 Apr 2009, 06:13 PM
The last comment can be ignored I figured that one out.  It was how I was pulling the file from the DB.
0
Genady Sergeev
Telerik team
answered on 29 Apr 2009, 01:22 PM
Hello John,

I have created sample project using the very code you provided, including the stored procedure and the data table, however everything is normal, I don't observe any errors. I uploaded and save RadControls.pdf - size 50.8 mb. When MaxFileSize was set to "20000" the uploaded file was not saved to the DB but moved to the InvalidFiles collection instead. Please find my test project along with my test database as an attachment. Does the error persist on your side?

Best wishes,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Upload (Obsolete)
Asked by
John
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
John
Top achievements
Rank 1
Share this question
or