This post is in response to support question Q241501 “Question Details: Upload default content types”. If you need a short answer then its all types by default. If you want a little holiday reading and to learn a couple of new skills the read the long answer.
The DevExpress controls are rich controls and some times you have to dig a little for the answer. I spent the better part of the last 2,000 hours writing the Professional DevExpress ASP.NET Controls and haven’t come close to having all of these bits and details available for instant recall (but that’s why our support center is here and why the technical evangelists are here, to help).
Add an ASPxUploadControl to a Web form. Add a button or use the ASPxUploadControl’s ShowUploadButton property to show the upload button. Define a ClientInstanceName for the ASPxUploadControl—I used uploader—and set the AutoPostBack to False. For the ASPxButton define client-side Click event and call uploader.UploadFile(). The control is ready to go.
<ClientSideEvents Click="function(s, e) {
uploader.UploadFile();
}" />
If you check out the help topic ms-help://MS.VSCC.v90/MS.VSIPCC.v90/DevExpress.NETv9.1/DevExpress.Web/CustomDocument5494.htm you will see that
If this property (ASPxUploadControl.ValidationSettings.AllowedContentTypes) is not set (that is, it's set to an empty string), an end-user is allowed to upload files of all types. You can recognize the uploaded file's type by reading it from the System.Web.HttpPostedFile.ContentType property accessed via the UploadedFile.PostedFile property in this case.
if you really want to see what is going on download a copy of Fiddler—at http://www.fiddler2.com/fiddler2/version.asp--and point it at your sample and you can explore what your web server sees. If you are using Cassini—the built-in server instead of IIS then change the URL to use the fiddler filter. For example, to point Fiddler at the demo below run the demo and the change the URL to
http://ipv4.fiddler:5251/UploadControlOriginalFileName/Default.aspx
Remember to set the port to whatever port Cassini is using. This is available from the development server which can be displayed from the taskbar in Windows. Using Fiddler for debugging was introduced in Chapter 2 of Professional DevExpress ASP.NET Controls in the section “Enabling Callback Compression”.
Figure 1: Fiddler is showing you how your web server is seeing interactions as depicted here.
Figure 2: The development server picks its own port each time it starts.
Here is some sample ASPX (Listing 1) and the code-behind that will permit you to verify this information.
Listing 1: Uploading any files is supported by default.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register assembly="DevExpress.Web.v9.2, Version=9.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxUploadControl" tagprefix="dxuc" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v9.2, Version=9.2.8.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dxe" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxuc:ASPxUploadControl ID="ASPxUploadControl1" runat="server" Height="27px"
Width="208px" ClientInstanceName="uploader">
</dxuc:ASPxUploadControl>
<br />
<dxe:ASPxButton ID="ASPxButton1" runat="server" Text="Upload" AutoPostBack="False">
<ClientSideEvents Click="function(s, e) {
uploader.UploadFile();
}" />
</dxe:ASPxButton>
</div>
</form>
</body>
</html>
Listing 2: This code stores whatever kind of file you post on the server.
Imports System.Diagnostics
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub ASPxUploadControl1_FileUploadComplete(ByVal sender As Object, _
ByVal e As DevExpress.Web.ASPxUploadControl.FileUploadCompleteEventArgs) _
Handles ASPxUploadControl1.FileUploadComplete
EventLog.WriteEntry("Application", String.Format("Uploaded: {0}", e.UploadedFile.FileName))
Dim ext As String = Path.GetExtension(e.UploadedFile.FileName)
Using stream As FileStream = New FileStream( _
Server.MapPath("~\Data\") + "uploadedfile" + ext, FileMode.CreateNew)
stream.Write(e.UploadedFile.FileBytes, 0, e.UploadedFile.FileBytes.Length)
End Using
End Sub
End Class
Happy Holidays!