15.3. Processing an Uploaded File Without Storing It on the Filesystem


You want a user to be able to upload a file to the web server for immediate processing, without having to first store the file.


Implement the solution described in Recipe 15.2 but instead of writing the file to the filesystem, use the input stream containing the uploaded file to process the data.

For the .aspx file, follow the steps for implementing the .aspx file in Recipe 15.2 and then, if you like, add a control that will show the results of the processing—for example, a DataGrid control to display the contents of an uploaded XML file.

In the code-behind file for the page, use the .NET language of your choice to:

  1. Verify, in the Upload button click event handler, that the file has been uploaded—that is, that the length of the filename and the file contents are both greater than 0—and (if appropriate) that it is a valid XML file.

  2. Load the updated data and, if you elected to include a control for showing the contents of the uploaded file, bind the uploaded data to the control—for example, a DataGrid control.

Example 15-8 through Example 15-10 show the .aspx file and VB and C# code-behind files for an application we’ve written to illustrate this solution. The initial output is identical to Recipe 15.2s example output and is shown in Figure 15-3.


This recipe demonstrates the concept of uploading files and processing them without having to store them to the local filesystem, as you might do ...

Get ASP.NET Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.