Get Mime Type From File Extension : Mime Type « Network « C# / C Sharp






Get Mime Type From File Extension

 

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using System.Text;

namespace OperatorModule
{
    public static class Utilities
    {

        public static string GetMimeTypeFromFileExtension(string extension)
        {
            string mimeType = "";
            extension = extension.ToLower();
            switch (extension)
            {
                case ".png":
                    mimeType = "image/png";
                    break;
                case ".jpg":
                    mimeType = "image/jpg";
                    break;
                case ".bmp":
                    mimeType = "image/bmp";
                    break;
                case ".gif":
                    mimeType = "image/gif";
                    break;
                case ".doc":
                    mimeType = "document/doc";
                    break;
                case ".docx":
                    mimeType = "document/docx";
                    break;
                case ".xls":
                    mimeType = "document/xls";
                    break;
                case ".xlsx":
                    mimeType = "document/xlsx";
                    break;
                case ".pdf":
                    mimeType = "document/pdf";
                    break;
                case ".rtf":
                    mimeType = "docuemnt/rtf";
                    break;
                case ".zip":
                    mimeType = "archive/zip";
                    break;
                case ".rar":
                    mimeType = "archive/rar";
                    break;
                default:
                    mimeType = "binary/other";
                    break;
            }
            return mimeType;
        }

    }
}

   
  








Related examples in the same category

1.Get Image Mime Type
2.Get Type Description From Mime Type