FileUpload.HasFile Property

Gets a value indicating whether the FileUpload control contains a file.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public:
property bool HasFile {
	bool get ();
}
/** @property */
public boolean get_HasFile ()

public function get HasFile () : boolean

Not applicable.

Property Value

true if the FileUpload contains a file; otherwise, false.

The HasFile property gets a value indicating whether the FileUpload control contains a file to upload. Use this property to verify that a file to upload exists prior to performing operations on the file. For example, before calling the SaveAs method to save the file to disk, use the HasFile property to verify that the file exists. If HasFile returns true, call the SaveAs method. If it returns false, display a message to the user indicating that the control does not contain a file.

The following code example demonstrates how to create a FileUpload control that performs error checking. Prior to saving the file, the HasFile method is called to verify that the control contains a file to upload. In addition, the File.Exists method is called to check whether a file with the same name already exists in the path. If it does, the name of the file to upload is prefixed with an underscore character before the SaveAs method is called. This prevents the existing file from being overwritten.

No code example is currently available or this language may not be supported.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: