This documentation is archived and is not being maintained.

HttpPostedFile.ContentType Property

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

[Visual Basic]
Public ReadOnly Property ContentType As String
[C#]
public string ContentType {get;}
[C++]
public: __property String* get_ContentType();
[JScript]
public function get ContentType() : String;

Property Value

The MIME content type of the uploaded file.

Example

The following example loops through all the files in the uploaded file collection and takes action when the MIME type of a file is US-ASCII.

[Visual Basic] 
Dim Loop1 As Integer
 Dim MyFileCollection As HttpFileCollection = Request.Files
 
 For Loop1 = 0 To MyFileCollection.Count - 1
    If MyFileCollection(Loop1).ContentType = "video/mpeg" Then
       '...
    End If
 Next Loop1
    

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

[C++] 
HttpFileCollection* MyFileCollection = Request->Files;
 
 for (int Loop1 = 0; Loop1 < MyFileCollection->Count; Loop1++)
 {
    if (MyFileCollection->Item[Loop1]->ContentType->Equals(S"video/mpeg"))
    {
       //...
    }
 }
    

[JScript] 
var myFileCollection : HttpFileCollection = Request.Files

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

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpPostedFile Class | HttpPostedFile Members | System.Web Namespace

Show: