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

RadUpload - Creating Duplicate Files

6 Answers 247 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Jako
Top achievements
Rank 1
Jako asked on 17 May 2012, 02:18 PM
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.

6 Answers, 1 is accepted

Sort by
0
Accepted
Kevin
Top achievements
Rank 2
answered on 18 May 2012, 01:11 PM
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.
0
Jako
Top achievements
Rank 1
answered on 18 May 2012, 01:44 PM
Hi Kevin

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

Cheers!
0
Peter Filipov
Telerik team
answered on 22 May 2012, 08:31 AM
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.
0
Andy
Top achievements
Rank 1
answered on 12 Jun 2012, 12:26 PM
Best Duplicate File Finder Is Free Duplicate File Finder From : http://www.ashisoft.com
0
joshuarobers
Top achievements
Rank 1
answered on 13 Mar 2013, 10:36 AM
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.
0
Jack
Top achievements
Rank 1
answered on 28 Jun 2013, 12:18 PM
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
Tags
Upload (Obsolete)
Asked by
Jako
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Jako
Top achievements
Rank 1
Peter Filipov
Telerik team
Andy
Top achievements
Rank 1
joshuarobers
Top achievements
Rank 1
Jack
Top achievements
Rank 1
Share this question
or