Exemplo n.º 1
0
        public static string GetSafeFilename(string filename)
        {
            if (string.IsNullOrEmpty(filename))
            {
                return(StringUtils.ToLower(StringUtils.GetShortGuid()));
            }

            return(string.Join("_", filename.Split(GetInvalidChars())));
        }
Exemplo n.º 2
0
 public static string ComputeHash(string filePath)
 {
     using (var md5 = MD5.Create())
     {
         using (var stream = File.OpenRead(filePath))
         {
             return(StringUtils.ToLower(BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "‌​")));
         }
     }
 }
Exemplo n.º 3
0
        public static bool IsInDirectory(string parentDirectoryPath, string path)
        {
            if (string.IsNullOrEmpty(parentDirectoryPath) || string.IsNullOrEmpty(path))
            {
                return(false);
            }

            parentDirectoryPath = StringUtils.ToLower(parentDirectoryPath.Trim().TrimEnd(Path.DirectorySeparatorChar));
            path = StringUtils.ToLower(path.Trim().TrimEnd(Path.DirectorySeparatorChar));

            return(parentDirectoryPath == path || path.StartsWith(parentDirectoryPath));
        }