Beispiel #1
0
        public ObjFileStream GetFileAvatarStream(int id)
        {
            if (id == 0)
            {
                return(null);
            }
            var file = _userRepository.Get(id);

            if (string.IsNullOrEmpty(file.AvatarFileName))
            {
                return(null);
            }
            var path = Path.Combine(CoreConfiguration.PathAvatar, file.AvatarFileName);

            FileInfo fileInf = new FileInfo(path);

            if (fileInf.Exists)
            {
                var result = new ObjFileStream();
                result.OriginalName = file.AvatarFileName;
                result.Data         = File.ReadAllBytes(path);
                return(result);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        internal static string FxConvertFileToMD5(string pFile)
        {
            string lHash = "";

            using (MD5 ObjMD5 = MD5.Create())
            {
                FileStream ObjFileStream;

                try
                {
                    ObjFileStream = File.OpenRead(pFile);
                }
                catch
                {
                    ObjFileStream = null;
                }

                if (ObjFileStream != null)
                {
                    byte[] ObjHash = ObjMD5.ComputeHash(ObjFileStream);

                    lHash = BitConverter.ToString(ObjHash).Replace("-", "").ToLowerInvariant();

                    ObjFileStream.Close();
                }

                ObjFileStream = null;
            }

            return(lHash);
        }