FileUpload.FileBytes Property

Returns an array of the bytes in a file that is specified using a FileUpload control.

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

[BindableAttribute(true)] 
public:
property array<unsigned char>^ FileBytes {
	array<unsigned char>^ get ();
}
/** @property */
public byte[] get_FileBytes ()

public function get FileBytes () : byte[]

Not applicable.

Property Value

A Byte array that contains the contents of the specified file.

Exception typeCondition

HttpException

The entire file was not read.

The FileUpload control does not automatically read the file from the client. You must explicitly provide a control or mechanism to allow the user to submit the specified file. For example, you can provide a button that the user can click to upload the file. The code that you write to save the specified file could call the FileBytes property, which returns the contents of the file.

Before calling the FileBytes property, you should use the HasFile property to verify that the FileUpload control contains a file to upload. If the HasFile returns true, call the FileBytes property. If it returns false, display a message to the user indicating that the control does not contain a file. If you do not provide error-handling code to verify that a file exists, an attempt to save a nonexistent file throws an HttpException exception.

The following code example demonstrates how to create a FileUpload control. When the user clicks the Upload file button, the contents of the file are displayed as bytes in a text box on the page. This example uses the FileBytes property to upload the entire file.

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: