public static string IncrementNameSuffixToLastName(string currentName, int parentNodeId)
{
currentName = RepositoryPath.GetFileName(currentName);
var ext = Path.GetExtension(currentName);
string nameBase;
bool inValidNumber;
var fileName = Path.GetFileNameWithoutExtension(currentName);
ContentNamingHelper.ParseSuffix(fileName, out nameBase, out inValidNumber);
var lastName = DataProvider.Current.GetNameOfLastNodeWithNameBase(parentNodeId, nameBase, ext);
// if there is no suffixed name in db, return with first variant
if (lastName == null)
return String.Format("{0}(1){1}", nameBase, ext);
// there was a suffixed name in db in the form namebase(x), increment it
// car(5)-> car(6), car(test)(5) -> car(test)(6), car(test) -> car(guid)
string newNameBase;
var newName = ContentNamingHelper.IncrementNameSuffix(lastName, out newNameBase);
// incremented name base differs from original name base (for example 'car(hello)(2)' and 'car(5)')
// edge case, use guid with original namebase
if (newNameBase != nameBase)
return String.Format("{0}({1}){2}", nameBase, Guid.NewGuid().ToString(), ext);
// incremented name base and original name base are equal, so incremented name is correct (eg 'car(2)')
return newName;
}
public static string IncrementNameSuffix(string name, out string nameBase)