Pages

Monday, February 11, 2008

How to Upload a larger size file into the web server

In the button click event you can write following code to upload a file in to the web server...

(Code Behind file)

private void Submit1_ServerClick(object sender, System.EventArgs e)
{

if( (uploadfile.PostedFile != null ) && (uploadfile.PostedFile.ContentLength > 0 ) )
{

string fn = System.IO.Path.GetFileName(uploadfile.PostedFile.FileName);
string SaveLocation = Server.MapPath("Data") + "\\" + fn;

try
{

uploadfile.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");

}
catch ( Exception ex )
{

Response.Write("Error: " + ex.Message);
}
}

else
{

Response.Write("Please select a file to upload.");

}
}

Then you should change the httpRuntime section in the Web.config file as follows...


<
httpRuntime
executionTimeout="90"
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>

0 comments: