RadUpload - Creating Duplicate Files

Thread is closed for posting
7 posts, 1 answers
  1. Jako
    Jako avatar
    107 posts
    Member since:
    Apr 2012

    Posted 17 May 2012 Link to this post

    Hi everyone

    I have multiple RadUpload controls, the problem is that a client may upload two files, with the same filename, so what I have done is create a simple File.Exists check and then saving the file, but it seems its saving each file before it even gets to my code. So its always creating a duplicate file.
    I understand that this is happening because the RadUpload sends the file to the server automatically on postback, is there a way to "manually" upload each file?

    Here is a sample of my code. I have many uploads, so I created an Array
    //LOG DOCUMENT ENTRIES
    RadUpload[] allUploads = new RadUpload[25] { uxUpload1, uxUpload2,..... };
    string fileToWritePath = "";
    string fileNameToSave = "";
     
    foreach (RadUpload uploadControl in allUploads)
    {
        foreach (UploadedFile f in uploadControl.UploadedFiles)
        {
            fileToWritePath = uploadControl.TargetPhysicalFolder + @"\" + f.FileName;
     
            if (File.Exists(fileToWritePath))
            {
                fileNameToSave = f.GetNameWithoutExtension().ToString() + "_" + DateTime.Now.ToString().Replace(":", "").Replace("/", "") + f.GetExtension().ToString();
                f.SaveAs(uploadControl.TargetPhysicalFolder + @"\" + fileNameToSave);
            }
            else
            {
                fileNameToSave = f.GetName();
                f.SaveAs(uploadControl.TargetPhysicalFolder + @"\" + fileNameToSave);
            }
     
            Document document = new Document(fileNameToSave, documenPath, 0, user.UserID);
        }
    }

    Any ideas?

    Thank you.
  2. Answer
    Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 18 May 2012 Link to this post

    Hello Jako,

    If you don't set the TargetFolder property on your RadUpload, then it will not automatically upload your file. Once, you remove that property, you're code will work, but you will need to set the full path in your code.

    I hope that helps.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jako
    Jako avatar
    107 posts
    Member since:
    Apr 2012

    Posted 18 May 2012 Link to this post

    Hi Kevin

    Thanks, code is working 100% as expected and just in time for the weekend.

    Cheers!
  5. Peter Filipov
    Admin
    Peter Filipov avatar
    1028 posts

    Posted 22 May 2012 Link to this post

    Hi Jako,

    You can use the following event too.

    All the best,
    Peter Filipov
    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.
  6. Andy
    Andy avatar
    1 posts
    Member since:
    Jun 2012

    Posted 12 Jun 2012 Link to this post

    Best Duplicate File Finder Is Free Duplicate File Finder From : http://www.ashisoft.com
  7. joshuarobers
    joshuarobers avatar
    1 posts
    Member since:
    Mar 2013

    Posted 13 Mar 2013 Link to this post

    I've recently found a software "Duplicate Files Deleter", and it can help you with this. Check http://DuplicateFilesDeleter.com , download it and you can find and delete duplicate files safely. There is a video to explain the process. Pretty nice solution.
  8. Jack
    Jack avatar
    1 posts
    Member since:
    Jun 2013

    Posted 28 Jun 2013 Link to this post

    Thank you Andy,
    but I do not think that I can agree with you :D
    Best Duplicate File Finder Is Free Duplicate File Finder From : http://www.mindgems.com
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017