Help us to translate this website and improve this translation!
English | Castellano

How to Use the FileUpload AJAX Control


As a preview to the explanation of the usage of HttpPostedFileAJAX, we first see what HttpPostedFileAJAX is. So, the HttpPostedFileAJAX is to the FileUploadAJAX as the HttpPostedFile classic is to the FileUpload classic.

Perhaps this is a good definition conceptually, but a better definition would be to see all of its properties to help understand the example of usage of the HttpPostedFileAJAX:
  • FileName: Name of the original file, as it is listed on the computer.
  • FileName_SavedAs: Path (Directory + Name) that we have given to the file upon storing it to the system (applicable only when having done a Save).
  • FileName_Path: Path formatted so that it is accessible by normal HTML.
  • ContentType: The MIME type of the content of the file. Useful to filter what types of files we are going to admit. All of the examples are filtered to only accept GIF images whose ContentType is "image/gif".
  • Type:Is an enumerator "FileType" that assists ContentType to ascertain the type of file being dealt with. Basing on the ContentType (never the extension of the file), allows us to distinguish the following types of files:
  • image: a file of any image: .gif, .jpg, .png, .bmp, etc.
  • audio: a file of any audio: .mp3, .wav, etc.
  • video: a file of general video: .mpg, .avi, etc.
  • text: a file that can be read like text. Can be flat text, an HTML file, a CSS file, an XML file, etc.
  • office: files used in the Office series of programs. (Word, Excel, PowerPoint, Access, Publisher, Project, etc.).
  • zip: ZIP compressed files.
  • application: Executable files that are not Office or ZIP files.
  • others: If the ContentType is known, but the file doesn’t match any other listed Type.
  • unknown: When the ContentType is not known.
  • ContentLength: Length (in bytes) of the file. Also useful to limit maximum file size. All of the examples on this website prohibit files larger than 5KB
  • responseMessage_Uploaded_Saved: Message that is displayed on screen when a file was successfully saved. Defaults to:
    "<a href="{3}" target="_blank">{0}</a> (>i>{1}>/i>) {2}KB".
    • {0} = FileName
    • {1} = ContentType
    • {2} = ContentLength
    • {3} = path for FileName_SavedAs
  • responseMessage_Uploaded_NotSaved: Message that is displayed on screen when a file has not been properly stored. Defaults to: "{0} is not saved." Where {0} = FileName
  • Saved: Boolean indicating whether the file has been stored correctly or not.
  • Deleted: Boolean indicating whether the file was deleted after you have uploaded.
  • responseMessage_Uploaded:If there have been no changes, this is the message that the user sees after uploading the file. If the file was saved successfully display “responseMessage_Uploaded_Saved”, otherwise “responseMessage_Uploaded_NotSaved”.