Uploading files whose size> 1MB and save to a folder

Posted by Nkkppp under ASP.NET on 8/8/2012 | Points: 10 | Views : 1365 | Status : [Member] | Replies : 0
I am trying to upload files to a folder on my harddisk whose size is greater than 500kb but i always get the message Http Error 400 BAD REQUEST . IIS is not installed on my profile so i didnt add <system.webserver> settings to the web.config file ('m using ASP.Net Development server i.e inbuilt)
As per my knowledge i had made changes to the web.config file as below

<configuration>
<connectionStrings>
<add name="connection" connectionString="server=PRATHAPG\SQLEXPRESS;database=Prathap;trusted_connection=true"/>
</connectionStrings>
<system.web>

<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength="204800" executionTimeout="3600" maxQueryStringLength="1024000"/>
</system.web>

</configuration>


The code for uploading the files


SqlConnection Cn;
SqlCommand Cmd;
SqlDataAdapter Da;
DataSet Ds;

protected void Page_Load(object sender, EventArgs e)
{
string conn = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
Cn = new SqlConnection(conn);
Ds = new DataSet();
Cmd = new SqlCommand();
Cmd.Connection = Cn;

}
protected void btnupload_Click(object sender, EventArgs e)
{
if (ful.HasFile)
{
string path = "~/Docs/" + ful.FileName;
string filename = Path.GetFileName(ful.PostedFile.FileName);
string fileExtension = Path.GetExtension(ful.PostedFile.FileName.ToLower());
if (fileExtension == ".pdf" || fileExtension == ".txt" || fileExtension == ".docx" || fileExtension == ".doc" || fileExtension == ".xls" || fileExtension == ".xlsx" || fileExtension == ".ppt" || fileExtension == ".pptx")
{
string documentType = string.Empty;
switch (fileExtension)
{
case ".pdf":
documentType = "application/pdf";
break;
}

ful.SaveAs(Server.MapPath(path));
Cmd.CommandText = "Files_Insert";
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.Parameters.AddWithValue("@Filename", filename);
Cmd.Parameters.AddWithValue("@Contenttype", documentType);
Cmd.Parameters.AddWithValue("@Fileurl", path);
Cn.Open();
Cmd.ExecuteNonQuery();
Cn.Close();
lblmsg.Text = "Uploaded Successfully";
}
else
lblmsg.Text = "Only Pdf,Word,Excel,Text files can be Uploaded";



Can you please suggest any other alternative and let me know the reason y i am not able to upload files whose size > 500KB even when i added necessary settings in web.config file.




Responses

(No response found.)

Login to post response