Get posted file's content type
FileUpload is an asp.net web server control. FileUplaod control allow us to upload a file to
web server.
FileUpload.PostedFile property allow us to get the underlying HttpPostedFile object for a file that is uploaded by using the FileUpload server control. PostedFile property value type is HttpPostedFile.
FileUpload control's PostedFile property has few sub properties. by accessing those sub properties we can get additional information about uploaded file. PostedFile ContentType sub property allow us to get the MIME content type of the uploaded file.
we can access ContentType property as FileUpload.PostedFile.ContentType. the ContentType property value data type is System.String which represents the MIME content type of the uploaded file.
the following asp.net c# example code demonstrate us how can we get the posted file's content type programmatically in an asp.net application
FileUpload.PostedFile property allow us to get the underlying HttpPostedFile object for a file that is uploaded by using the FileUpload server control. PostedFile property value type is HttpPostedFile.
FileUpload control's PostedFile property has few sub properties. by accessing those sub properties we can get additional information about uploaded file. PostedFile ContentType sub property allow us to get the MIME content type of the uploaded file.
we can access ContentType property as FileUpload.PostedFile.ContentType. the ContentType property value data type is System.String which represents the MIME content type of the uploaded file.
the following asp.net c# example code demonstrate us how can we get the posted file's content type programmatically in an asp.net application
FileUploadPostedFileContentType.aspx
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
string uploadFolder = Request.PhysicalApplicationPath + "UploadFile\\";
FileUpload1.SaveAs(uploadFolder + FileUpload1.FileName);
Label1.Text = "This file uploaded successfully!<br />Posted File Content Type: "
+ FileUpload1.PostedFile.ContentType;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net FileUpload example: how to get posted file content type after upload file</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Red">asp.net FileUpload example: Posted File Content Type</h2>
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
Font-Italic="true"
Font-Bold="true"
ForeColor="Maroon"
>
</asp:Label>
<br /><br />
<asp:FileUpload
ID="FileUpload1"
runat="server"
BackColor="DarkGreen"
ForeColor="LawnGreen"
Font-Italic="true"
Font-Bold="true"
/>
<asp:Button
ID="Button1"
runat="server"
Font-Bold="true"
ForeColor="DarkGreen"
OnClick="Button1_Click"
Text="Upload This File"
/>
<br /><br />
</div>
</form>
</body>
</html>



- asp.net FileUpload example: how to upload file with specific extension
- asp.net FileUpload validation example: how to validate FileUpload control (file upload)
- asp.net FileUpload example: how to check whether FileUpload control has file
- asp.net FileUpload example: how to check (handle) error when upload a file
- asp.net FileUpload example: how to get posted file full name after upload a file
- asp.net FileUpload example: how to get posted file content length (size) after upload file
- asp.net FileUpload example: how to rename file when upload (change file name when upload)
- FileUpload example: how to use FileUpload control in asp.net