Example #1
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));
        }