ContentType Property

Object: SoftArtisans.SAFile
Syntax: ContentType
Type: String
Read/Write: Read/Write
Description:

This property contains the MIME Content Type of the file, which is useful in determining the contents of the file.

It has been our experience that Netscape Navigator version 4 returns creative and diverse Content Types, depending on the file being uploaded. Internet Explorer typically returns the lowest common denominator that is "application/octet-stream".

See also the ContentType propertyfor the SAFileUp object.

Examples:
ASP <%
'--- Get the uploaded file's content-type and
'--- assign it to a variable.
strContentType = fileUpload.Form("MyFile").ContentType

'--- Use the Select Case Condition to restrict the file type.
Select Case LCase(strContentType)
Case "image/gif"
fileUpload.Form("MyFile").Save
Response.Write fileUpload.Form("MyFile").ShortFilename & _
" has been saved."

Case "image/pjpeg"
fileUpload.Save
Response.Write fileUpload.Form("MyFile").ShortFileName & _
" has been saved."

Case Else
fileUpload.Delete
Response.Write "You can only upload gif and jpeg files."
End Select
%>
C# String strContentType =
((SaFile)fileUpload.Form["MyFile"]).ContentType;

switch(strContentType)
{
case "image/gif":
file.Save();
break;
case "image/pjpeg":
file.Save();
break;
default:
file.Delete();
break;
}
VB.NET Dim strContentType As String = _
CType(fileUpload.Form("MyFile"), SaFile).ContentType

Select Case strContentType
Case "image/gif"
file.Save
Case "image/pjpeg"
file.Save
Case Else
file.Delete
End Select

Copyright © 2010 SoftArtisans, Inc. All rights reserved.