10 Answers, 1 is accepted
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.
<
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
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.
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.
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:
|
Version Information: Microsoft .NET Framework Version:2.0.50727.3074; ASP.NET Version:2.0.50727.3074
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.