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

RadUpload cancel process of current uploading file

1 Answer 377 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 30 Jan 2012, 06:44 AM
Hi !!

I am using RadUpload to upload single video file at a time. The code in aspx file is

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
    <script type="text/javascript">
 
        function checkFileExists() {
 
                    var count = 0;
                    var upld = $find('<%= RadUpload1.ClientID %>');
                    var input = $find('<%= RadUpload1.ClientID %>').getFileInputs();
                    var fileName = input[0].value.toLowerCase();
                    var allowOverWriteFile = true;
 
                    //To check whether the selected file is with mp4 extension or not
            if (upld.isExtensionValid(fileName) == false) {
                        alert("You are allowed to upload only MP4 files. Kindly select the MP4 video and upload again.");
                        return false;
                    }
 
            //To confirm overwrite
                    count = document.getElementById('<%= txtUrl.ClientID %>').options.length;
 
                    for (var i = 0; i < count; i++) {
 
                        if (fileName == document.getElementById('<%= txtUrl.ClientID %>').options[i].value.toLowerCase()) {
 
                            allowOverWriteFile = confirm("This file is already exists. Are you sure want to overwrite it?");
                            return allowOverWriteFile;
                        }
                    }
                    return true;
                }
 
    </script>
</telerik:RadScriptBlock>
 
<telerik:RadProgressManager ID="RadProgressManager1" runat="server" Width="245px"/>
<telerik:RadProgressArea ID="RadProgressArea1" runat="server" ProgressIndicators="TotalProgressBar,CurrentFileName,RequestSize,TransferSpeed" Skin="Default" Width="245px" DisplayCancelButton="true">
</telerik:RadProgressArea>
 
<telerik:RadUpload ID="RadUpload1" runat="server" OverwriteExistingFiles="true" ControlObjectsVisibility="None" InitialFileInputsCount="1" AllowedFileExtensions=".mp4" Width="100px" allowedmimetypes="application/mp4,video/mp4">
</telerik:RadUpload>
 
<asp:Button ID="BtnUpload" runat="server" Text="Upload" OnClientClick="return checkFileExists()" onclick="BtnUpload_Click" />


on clicking "BtnUpload" I have logic to save file on server directory.


aspx.cs file is :

protected void BtnUpload_Click(object sender, EventArgs e)
{
            //int counter = 0;
 
            string targetFolder = string.Empty;
            string targetFileNameAndPath = string.Empty;
            string targetFileNameWithExtension = string.Empty;
            string targetFileNameWithoutExtension = string.Empty;
            string tempFilename = string.Empty;
 
            if (RadUpload1.UploadedFiles.Count > 0)
            {
                if (RadUpload1.InvalidFiles.Count > 0)
                {
                    labelInvalidResults.Visible = true;
                }
                else
                {
                     
                    labelInvalidResults.Visible = false;
 
                    targetFolder = Server.MapPath(ResolveUrl("~/directoryName/"));
                    targetFileNameAndPath = Path.Combine(targetFolder, RadUpload1.UploadedFiles[0].GetNameWithoutExtension() + RadUpload1.UploadedFiles[0].GetExtension());
                    targetFileNameWithExtension = RadUpload1.UploadedFiles[0].GetNameWithoutExtension() + RadUpload1.UploadedFiles[0].GetExtension();
                    targetFileNameWithoutExtension = RadUpload1.UploadedFiles[0].GetNameWithoutExtension();
                    tempFilename = targetFileNameWithoutExtension.Replace("_", " ");
 
                    RadUpload1.UploadedFiles[0].SaveAs(targetFileNameAndPath);
 
 
                    Thread uploadVideoThread = new Thread(() => convertVideoFile(targetFileNameAndPath, targetFileNameWithExtension, targetFileNameWithoutExtension));
                    uploadVideoThread.Start();
                     
                }
            }
}


My web.config file is :

<system.web>
    <httpModules>
        <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule" />
    </httpModules>
        <httpRuntime maxRequestLength="102400" executionTimeout="3600" />
</system.web>
 
<system.webServer>
    <modules>
                <add name="RadUploadModule" preCondition="integratedMode" type="Telerik.Web.UI.RadUploadHttpModule" />
        </modules>
    <handlers>
        <add name="Telerik_RadUploadProgressHandler_ashx" verb="*" preCondition="integratedMode" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler" />
    </handlers>
</system.webServer>


The problem is I want to cancel the upload process of current file (during uploading process is going on )on clicking "Cancel" button shown in Progressarea. How can be it possible?. At present when user clicks on "cancel" button, it just closes the uploading progress dialog, but still physical file gets uploaded on serverside. It should not be uploaded alt all.

1 Answer, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 30 Jan 2012, 06:34 PM
Hi Eric,

If you want to stop the proccess of uploading, you will have to use RadAsyncUpload. You can check out it's functionality and how you can use a RadProgressArea with it in the following demo:
http://demos.telerik.com/aspnet-ajax/upload/examples/async/monitorprogress/defaultcs.aspx?product=asyncupload 
 
Regards,
Bozhidar
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
Upload (Obsolete)
Asked by
Eric
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Share this question
or