This documentation is archived and is not being maintained.

HttpPostedFile.ContentType Property

Gets the MIME content type of a file sent by a client.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public string ContentType { get; }
/** @property */
public String get_ContentType ()

public function get ContentType () : String

Property Value

The MIME content type of the uploaded file.

The following code example shows how to loop through all the files in the uploaded file collection and take action when the MIME type of a file is US-ASCII.

HttpFileCollection MyFileCollection = Request.Files;
 
 for (int Loop1 = 0; Loop1 < MyFileCollection.Count; Loop1++)
 {
    if (MyFileCollection[Loop1].ContentType == "video/mpeg")
    {
       //...
    }
 }
    

HttpFileCollection myFileCollection = get_Request().get_Files();

for (int loop1 = 0; loop1 < myFileCollection.get_Count(); loop1++) {
    if (myFileCollection.get_Item(loop1).get_ContentType().
        Equals("video/mpeg")) {
            //...
    }
}

var myFileCollection : HttpFileCollection = Request.Files

for(var i=0; i < myFileCollection.Count; i++){
  if(myFileCollection[i].ContentType == "video/mpeg"){
      //...
  }
}


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: