Hi Martin,
The provided code works correctly, but I made some changes in it in order to use the built in methods in the VirtualUtility class.
The reworked code looks like this:
public
override
string
CopyFile(
string
sourcePath,
string
newPath)
{
if
(FileExists(sourcePath) && FileExists(newPath))
{
// The original approach:
//var path = newPath.Substring(0, newPath.LastIndexOf("/") + 1);
//var name = newPath.Substring(newPath.LastIndexOf("/") + 1);
// TELERIK's solution:
string
path = VirtualPathUtility.GetDirectory(newPath);
// gets the directory
string
name = VirtualPathUtility.GetFileName(newPath);
var extension = VirtualPathUtility.GetExtension(newPath);
// The original approach (tis code is not necessory) :
//if (name.IndexOf(".") >= 0)
//{
// extension = name.Substring(name.LastIndexOf("."));
// name = name.Substring(0, name.LastIndexOf("."));
//}
var fileNumber = 0;
while
(FileExists(newPath))
{
newPath =
string
.Format(
"{0}{1} [{2}]{3}"
, path, name, ++fileNumber, extension);
}
}
return
base
.CopyFile(sourcePath, newPath);
}
The idea is excellent and I believe that it will be useful for the Telerik community. Your Telerik points are updated.
Greetings,
Fiko
the Telerik team