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

Duplicate file checking while adding the attachment in RadAsyncUpload

1 Answer 436 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Suresh
Top achievements
Rank 1
Suresh asked on 05 Oct 2013, 02:17 PM

Hi All,

I am using the RadAsyncUpload in my app. So what I need as follows whenever we select any attachment to upload how to add the duplicate file checking from the client side, and that to while picking the attachments itself.

 

Anybody knows how to do this?.

 

Thanks,

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Oct 2013, 07:36 AM
Hi Mohinder Goswami,

It is not possible to access the uploaded files while attaching a file in RadAsyncUpload. So one suggestion is you can access the already uploaded file names on server side and keep it in a hidden field and OnClientFileSelected event you can check the duplication using that hidden field as follows.

ASPX:
<telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" OnClientFileSelected="OnClientFilesSelected1"
    MultipleFileSelection="Automatic" TargetFolder="~/Uploads">
</telerik:RadAsyncUpload>
<asp:HiddenField ID="hiddenfield1" runat="server" />

JavaScript:
<script type="text/javascript">
    function OnClientFilesSelected1(sender, args) {
        var hiddenfield1=document.getElementById("<%= hiddenfield1.ClientID %>");
        var filenames = hiddenfield1.value;
        var currentfiles = args.get_fileName();
        var filename = filenames.split(",");
        for (var i = 0; i < filename.length; i++) {
            if (filename[i] == currentfiles) {
                alert("Duplicate File");
                break;
            }
        }
    }
</script>

C#:
string str=string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
    string path = Server.MapPath(RadAsyncUpload1.TargetFolder);
    DirectoryInfo d = new DirectoryInfo(path);
    FileInfo[] Files = d.GetFiles();
    foreach (FileInfo file in Files)
    {
        str += file.Name + ",";
    }
     hiddenfield1.Value = str;
}

Thanks,
Shinu.
Tags
AsyncUpload
Asked by
Suresh
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or