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

File validation does not work for me!

1 Answer 64 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
elaheh
Top achievements
Rank 1
elaheh asked on 03 Jul 2012, 05:58 AM
Hi,
I have tried to use the codes are for validation in Asyncupload and uplod tools in these links:
http://demos.telerik.com/aspnet-ajax/upload/examples/async/validation/defaultcs.aspx?product=asyncupload
http://www.telerik.com/help/aspnet-ajax/upload-client-side-validation.html

But none of them works correcrtly! when I select a non-valid file (for example a pdf file which its extension is changed to jpg), it does not prevent uploading it.

this is all my code with Asyncupload:
<asp:Content ID="Content2" ContentPlaceHolderID="content2" Runat="Server">
<script type="text/javascript">
      //<![CDATA[
        function validationFailed(sender, eventArgs) {
            $(".ErrorHolder").append("<p>Validation failed for '" + eventArgs.get_fileName() + "'.</p>").fadeIn("slow");
        }
      //]]>
    </script>
<telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
    </telerik:RadStyleSheetManager>
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.Core.js">
            </asp:ScriptReference>
 
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.jQuery.js">
            </asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.jQueryInclude.js">
            </asp:ScriptReference>
        </Scripts>
    </telerik:RadScriptManager>
<telerik:RadButton ID="uploadbtn" runat="server" Text="upload"
        onclick="uploadbtn_Click">
    </telerik:RadButton>
    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server"
        AllowedFileExtensions="jpg,jpeg"
        TargetFolder="~/upload" OnClientValidationFailed="validationFailed"
        onfileuploaded="RadAsyncUpload1_FileUploaded" >
        <FileFilters>
        <telerik:FileFilter Description="Images(jpeg;jpg)" Extensions="jpeg,jpg" />
    </FileFilters>
    </telerik:RadAsyncUpload>

and in code behind for upload button:
protected void RadAsyncUpload1_FileUploaded(object sender, Telerik.Web.UI.FileUploadedEventArgs e)
    {
        Label fileName = new Label();
        fileName.Text = e.File.FileName;
 
 
        if (e.IsValid)
        {
            Response.Write(fileName + "::true");
        }
        else
        {
            Response.Write("false");
        }
    }
 Is there anything missing from me?

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 04 Jul 2012, 11:52 AM
Hi Elaheh,

 
The validation is checking exactly the extension so if it is changed the expected behavior will be the file to be uploaded.

Hope this will explain the issue.

All the best,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
AsyncUpload
Asked by
elaheh
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or