i used this code in .ashx for upload pdf it fine when pdf size is less then 1 mb but if pdf file is larger than show error maxLimit
i used this code
<%@ WebHandler Language="C#" Class="pdfUploader" %>
using System;
using System.IO;
using System.Net;
using System.Web;
using System.Web.Script.Serialization;
using System.Drawing;
using System.Drawing.Drawing2D;
public class pdfUploader : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//Check if Request is to Upload the File.
if (context.Request.Files.Count > 0)
{
//Fetch the Uploaded File.
HttpPostedFile postedFile = context.Request.Files[0];
//Set the File Name.
string fileName = Path.GetFileName(postedFile.FileName);
string extension = Path.GetExtension(fileName);
if (extension.ToLower() != ".pdf")
{
string json2 = new JavaScriptSerializer().Serialize(
new
{
name = "Only PDF Format Accepted...",
name2 = "warning"
});
context.Response.StatusCode = (int)HttpStatusCode.OK;
context.Response.ContentType = "text/json";
context.Response.Write(json2);
context.Response.End();
return;
}
if (File.Exists(context.Server.MapPath("~/AdminPannel/UploadingPDF/") + fileName))
{
File.Delete(context.Server.MapPath("~/AdminPannel/UploadingPDF/" + fileName));
}
//save Pdf File into Folder
string folderPath = context.Server.MapPath(@"~/AdminPannel/UploadingPDF/") + fileName;
postedFile.SaveAs(folderPath);
//Send File details in a JSON Response.
string json = new JavaScriptSerializer().Serialize(
new
{
name = fileName + " " + "Has been Uploaded SucessFully...",
name2 = "success",
name3 = fileName
});
context.Response.StatusCode = (int)HttpStatusCode.OK;
context.Response.ContentType = "text/json";
context.Response.Write(json);
context.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}