ComponentOne ToolBar for ASP.NET AJAX: Upload for ASP.NET AJAX Task-Based Help > Validating Files > Validating File Extensions for Uploaded Files

Validating File Extensions for Uploaded Files

You can specify what type of files you would like C1Upload to automatically validate by assigning the file extensions to the ValidFileExtensions property.

Setting the ValidFileExtensions Property in Design View:

To set the ValidFileExtensions property, complete the following steps:

1.   Click the Design button to enter Design view.

2.   Right-click the C1Upload control to open its context menu and select Properties from the list.

The Properties window opens with the C1Upload’s control properties in focus.

3.   Set the ValidFileExtensions property to “doc, html, gif”.

4.   Press F5 to build the project and try adding files with extensions other than .doc, .html, and .gif. Notice that those files are not placed into the physical or virtual target folder since they didn’t meet the file extension requirements that you specified for the ValidFileExtensions property.

Setting the ValidFileExtensions Property in SourceView:

To set the ValidFileExtensions property, complete the following steps:

1.   Click the Source button to enter Source view.

2.   Place the ValidFileExtensions=".doc,.html,.gif" in the <cc1:C1Upload> tag so that the markup resembles the following:

 

<cc1:C1Upload id="C1Upload1" runat="server"

  ValidFileExtensions=".doc,.html,.gif" />

 

3.   Press F5 to build the project and try adding files with extensions other than .doc, .html, and .gif. Notice that those files are not placed into the physical or virtual target folder since they didn’t meet the file extension requirements that you specified for the ValidFileExtensions property.

Setting the ValidFileExtensions Property in the Code-behind file:

In the code-behind, assign the value of the ValidFileExtensions property to a string array, like the following:

1.   On the Visual Studio toolbar, click View | Code to enter Code view.

2.   Import the following namespace into your project:

      Visual Basic

Imports C1.Web.UI.Controls.C1Upload

      C#

using C1.Web.UI.Controls.C1Upload;

3.   Assign the value of the ValidFileExtensions property by adding the following code into the Page_Load event:

      Visual Basic

C1Upload1.ValidFileExtensions = New String() {".doc", ".html", ".gif"}

      C#

C1Upload1.ValidFileExtensions = new string[] {".doc", ".html", ".gif"};

4.   Press F5 to build the project and try adding files with extensions other than .doc, .html, and .gif. Notice that those files are not placed into the physical or virtual target folder since they didn’t meet the file extension requirements that you specified for the ValidFileExtensions property.


Send comments about this topic to ComponentOne.
Copyright © 1987-2010 ComponentOne LLC. All rights reserved.