Friday, February 19, 2010

File Uploader using asp.net c#

web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
<httpRuntime executionTimeout="90" maxRequestLength="200000" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>


  • Default.aspx.cs File
static string fn1;
protected void BtnUpload_Click(object sender, EventArgs e)
{
try
{
if ((FileUploader.HasFile) && (FileUploader.PostedFile.ContentLength > 0) && FileUploader.PostedFile.ContentLength <= 20000000)
{
fn1 = System.IO.Path.GetFileName(FileUploader.PostedFile.FileName);
string SaveLocation = Server.MapPath("public_files") + "\\" + fn1;FileUploader.PostedFile.SaveAs(SaveLocation);
lbMessage.Text = "Upload successess... Have a nice day...<a href='http://www.twitter.com/rodriguesjax'>Go to Twitter </a><p>Files saved to " + SaveLocation + "</p>";
}
else
{
lbMessage.Text = "please select a file less than 20MB and greater than 0MB.";
}
}
catch (Exception ex)
{
lbMessage.Text = "Sorry. Upload Failed : " + ex.Message;
}
}

No comments:

Post a Comment