This commit is contained in:
2020-06-25 16:00:39 +00:00
parent 248292fce2
commit 62a044e92e
2 changed files with 67 additions and 7 deletions

View File

@@ -644,6 +644,19 @@ namespace AyaNova.Util
return DateTime.Now.ToString("yyyyMMddHHmmssfff");
}
public static string StringToSafeFileName(string fileName)
{//https://stackoverflow.com/a/3678296/8939
if (string.IsNullOrWhiteSpace(fileName))
return "no_name";
char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
// Builds a string out of valid chars and an _ for invalid ones
var ret = new string(fileName.Select(ch => invalidFileNameChars.Contains(ch) ? '_' : ch).ToArray());
if (string.IsNullOrWhiteSpace(ret))
return "no_name";
return ret;
}
#endregion general utilities
}//eoc