AUTHOR: Marin Bratanov
DATE POSTED: April 13, 2018
In the ItemCommand event of the RadFileExplorer control, the OverwriteExistingFiles property always returns the server value and not the checkbox value from the Upload dialog. This can allow you to prevent the user from overwriting files if they already exist, regardless of their choice, based on some server logic.
In some cases you may want to know whether the "Overwrite if file exists?" checkbox is checked or not. Its initial value is determined by the OverwriteExistingFiles property and when files are uploaded the checkbox Checked property is evaluated before overwriting files, so that it can work together with the provider.
You can get a reference to the checkbox control and use its value by using the FindControl() method. Its ID is chkOverwrite. Here is a snippet that checks if the file already exists and prevents file overwrites (the built-in logic would also do that, this is just an example):
sender, RadFileExplorerEventArgs e)
userWantsToOverwriteFile = ((sender
fileExists = File.Exists(Server.MapPath(e.Path));
(fileExists && !userWantsToOverwriteFile)
When using a custom content provider, you do not need to perform such a check in your code. The file explorer checks if the file exists and whether the "overwrite" checkbox is checked before calling the StoreFile() method of the provider. So, if the file does not exist, or the user did not check the checkbox, your StoreFile method will not be called.
Here is an extract of the RadFileExplorer code that does this check:
(Stream stream = ContentProvider.GetFile(fullFileName))
errorMessage += uploadedFile.GetName() +
" : "
newFilePath = ContentProvider.StoreFile(uploadedFile, currentDir, lastFileName);