18.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 18.2. 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 18.2 and then, if you like, add a control that will show the results of the processing—for example, a
GridView 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:
Verify, in the Upload button click event handler, that the file has been uploaded—that is, that the
HasFileproperty of the
FileUploadcontrol is set to
True—and (if appropriate) that it is a valid XML file.
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
Examples 18-8, 18-9 through 18-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 18.2’s example output and is shown in Figure 18-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 with the contents ...