Export (0) Print
Expand All

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

Not applicable.

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 Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft