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

Override cancel and remove

3 Answers 116 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 09 Sep 2015, 03:06 PM

I am using a custom Http Handler as described at http://www.telerik.com/forums/radasyncupload-without-temporary-file to upload files directly to a database without using a temporary folder.  This is working correctly, however, if the user clicks 'cancel' or 'remove' the file is obviously not removed from my database.
Is there a way to override the cancel and remove operations so I can delete the files from my database?

 I've created a new class that inherits from AsyncUploadResult to add a FileID so this should be easy... if I just knew which fuction to override.  Thanks!

3 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 11 Sep 2015, 11:03 AM
Hi Michael,

RadAsyncUpload cannot remove uploaded file automatically. That's why you can create webservice which do that. Use jQuery to attach click event to "Cancel/Remove" buttons and call the service.
 
Regards,
Hristo Valyavicharski
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Michael
Top achievements
Rank 1
answered on 11 Sep 2015, 02:02 PM
In order to not re-invent the wheel, do you have any example code for attaching a jquery event to attach to these buttons in order to call a webservice?
0
Hristo Valyavicharski
Telerik team
answered on 14 Sep 2015, 11:59 AM
Sample with web method: 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>
        <script type="text/javascript">
            function fileRemoving(sender, args) {
                $.ajax({
                    type: "POST",
                    url: "Default.aspx/Remove",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    failure: function (response) {
                        alert(response.d);
                    }
                 });
            }
 
            function OnSuccess(response) {
                alert(response.d);
            }
 
        </script>
        <div>
            <telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1" OnClientFileUploadRemoving="fileRemoving"></telerik:RadAsyncUpload>
        </div>
    </form>
</body>
</html>

using System;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Web.Script.Services;
 
public partial class Default : System.Web.UI.Page
{
    [WebMethod]
    [ScriptMethod]
    public static int Remove()
    {
        // SQL query that removes file from the DB
        return 200;
    }
}

I hope this helps.

Regards,
Hristo Valyavicharski
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
AsyncUpload
Asked by
Michael
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Michael
Top achievements
Rank 1
Share this question
or