Thursday, June 29, 2006

ASP .NET 1.1 Upload Files

In ASP.NET framework 1.1, the html control can be represented by the tags < id="uploadfile" type= "file" runat="server">.

Sample Code
//Check that the file is not null
if (uploadfile.PostedFile != null)
{
// process the post file logic here.

//Example of saving the file as another file
this.uploadfile.PostedFile.SaveAs("C:\filename");

//Example of getting the name of the file
string filename = System.IO.Path.GetFileName(this.uploadfile.PostedFile.FileName);
}

But the catch of this method is that the file size is limited to 4 MB. In .NET framework 2.0, this file size can be adjusted easily. However, .NET 1.1 framework users have to add this line in the web.config file


< httpRuntime ="10000" executionTimeout="54000" >

This will increase the lenght of the file to 10 MB (recommended not more than 20 MB) and increase the time allowed to process the bigger file accordingly.


No comments:

Post a Comment