private string FindUniqueDocumentName(string libraryName, string documentName) { if (!Dataphoria.DocumentExists(libraryName, documentName)) { return(documentName); } int count = 1; int numIndex = documentName.Length - 1; while ((numIndex >= 0) && Char.IsNumber(documentName, numIndex)) { numIndex--; } if (numIndex < (documentName.Length - 1)) { count = Int32.Parse(documentName.Substring(numIndex + 1)); documentName = documentName.Substring(0, numIndex + 1); } string name; do { name = documentName + count.ToString(); count++; } while (Dataphoria.DocumentExists(libraryName, name)); return(name); }