PoshCode Archive  Artifact [e2d561c24c]

Artifact e2d561c24cd48af90476d59a4dc550965fea581e9c22f7063379f7db11619e28:

  • File Get-MimeType.ps1 — part of check-in [79170cebab] at 2018-06-10 13:47:48 on branch trunk — another way to retrieve mime type (user: greg zakharov size: 939)

# encoding: ascii
# api: powershell
# title: Get-MimeType
# description: another way to retrieve mime type
# version: 0.1
# type: function
# author: greg zakharov
# license: CC0
# function: Get-MimeType
# x-poshcode-id: 4935
# x-archived: 2017-03-01T10:39:56
# x-published: 2014-02-27T14:50:00
#
#
#requires -version 2.0
function Get-MimeType {
  <#
    .NOTES
        Author: greg zakharov
  #>
  param(
    [Parameter(Mandatory=$true, ValueFromPipeLine=$true)]
    [ValidateScript({Test-Path $_})]
    [String]$FileName
  )
  
  begin {
    Add-Type -AssemblyName System.Web
    $FileName = cvpa $FileName
  }
  process {
    ([AppDomain]::CurrentDomain.GetAssemblies() | ? {
      $_.FullName.Contains('System.Web')
    }).GetType(
      'System.Web.MimeMapping'
    ).GetMethod(
      'GetMimeMapping', [Reflection.BindingFlags]40
    ).Invoke(
      $null, @($FileName)
    )
  }
  end {}
}