Ejemplo n.º 1
0
        private static string GetMimeTypeByData(byte[] data)
        {
            string mimeType;

            MimeTypeHelper.TryGetMimeTypeByData(data, out mimeType);
            return(mimeType);
        }
Ejemplo n.º 2
0
        private static string GetMimeTypeByExtension(string fileName)
        {
            string mimeType;

            MimeTypeHelper.TryGetMimeTypeByExtension(fileName, out mimeType);
            return(mimeType);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the MimeType for the specified data.
        /// </summary>
        /// <param name="data"><see cref="Byte"/> <see cref="Array"/> containing the data to investigate.</param>
        /// <returns>The Mime Type for the <paramref name="data"/> if successfull; otherwise return 'unknown/unknown'.</returns>
        /// <exception cref="ArgumentNullException">thrown if the <paramref name="data"/> is <c>Null</c> or <c>Empty</c>.</exception>
        public static string GetMimeType(byte[] data)
        {
            if (data.IsNullOrEmpty())
            {
                throw new ArgumentNullException("data");
            }

            return(MimeTypeHelper.GetMimeTypeByData(data));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the MimeType for the specified file, based on it's extension if possible, otherwise on its content.
        /// </summary>
        /// <param name="file">The <see cref="FileInfo"/> instance to investigate.</param>
        /// <returns>The Mime Type for the file if successfull; otherwise return 'unknown/unknown'.</returns>
        /// <exception cref="ArgumentNullException">thrown if the <paramref name="file"/> is <c>Null</c> or Empty.</exception>
        /// <exception cref="FileNotFoundException">thrown if the file specified by the parameter <paramref name="file"/> does not exist.</exception>
        public static string GetMimeType(FileInfo file)
        {
            if (file.IsNull())
            {
                throw new ArgumentNullException("file");
            }

            return(MimeTypeHelper.GetMimeType(file.FullName));
        }
        public static string GetMimeType(this System.IO.Stream stream)
        {
            if (stream.IsNull())
            {
                throw new ArgumentNullException("stream");
            }

            return(MimeTypeHelper.GetMimeType(stream.ToByteArray()));
        }
        public static string GetMimeType(this byte[] data)
        {
            if (data.IsNull())
            {
                throw new ArgumentNullException("data");
            }

            return(MimeTypeHelper.GetMimeType(data));
        }
        public static string GetMimeType(this System.IO.FileInfo file)
        {
            if (file.IsNull())
            {
                throw new ArgumentNullException("file");
            }

            if (!file.Exists)
            {
                throw new FileNotFoundException(string.Format("{0} not found", file.FullName));
            }

            return(MimeTypeHelper.GetMimeType(file));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the MimeType for the specified file, based on it's extension if possible, otherwise on its content.
        /// </summary>
        /// <param name="fileName">The path to the file to investigate.</param>
        /// <returns>The Mime Type for the file if successfull; otherwise return 'unknown/unknown'.</returns>
        /// <exception cref="ArgumentNullException">thrown if the <paramref name="fileName"/> is <c>Null</c> or Empty.</exception>
        /// <exception cref="FileNotFoundException">thrown if the file specified by the parameter <paramref name="fileName"/> does not exist.</exception>
        public static string GetMimeType(string fileName)
        {
            if (fileName.IsNullEmptyOrWhiteSpace())
            {
                throw new ArgumentNullException("fileName");
            }

            if (!File.Exists(fileName))
            {
                throw new FileNotFoundException(string.Format("{0} not found", fileName));
            }

            string mimeType;

            if (!MimeTypeHelper.TryGetMimeTypeByExtension(fileName, out mimeType))
            {
                MimeTypeHelper.TryGetMimeTypeByData(new System.IO.FileInfo(fileName).OpenRead().ToByteArray(), out mimeType);
            }

            return(mimeType);
        }