ContentType Property
.NET Framework Class Library
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)
Visual Basic (Declaration)
Public ReadOnly Property ContentType As String
Visual Basic (Usage)
Dim instance As HttpPostedFile
Dim value As String

value = instance.ContentType
C#
public string ContentType { get; }
Visual C++
public:
property String^ ContentType {
    String^ get ();
}
JScript
public function get ContentType () : String

Property Value

Type: System..::.String
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.

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")
    {
       //...
    }
 }


JScript
var myFileCollection : HttpFileCollection = Request.Files

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


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
Page view tracker