TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
prabhu p
NA
181
115k
How to download a file from handler in asp.net
Nov 24 2016 6:23 AM
In web method
I am getting data in datatable and save in local path as excel file from there i want call handler and file want to download, while debugging everything is fine but file not downloading
[System.Web.Services.WebMethod]
public static void SaveME_Onlinedetails(string[] CartValues)
{
Objdt = OBJBLL.BLLLOADGRID(objboNova);
string strname = "ManualEntry";
ExcelFile ef = new ExcelFile();
ExcelWorksheet ws = ef.Worksheets.Add("Summary");
string filepath = "E:\\BackUp\\Hemachandraprabhu_18112016\\Novartis\\Novartis\\ManualEntry\\ManualEntry " + strname + ".XLS";
FileStream fs = File.Create(filepath);
ws.InsertDataTable(Objdt, "A1", true);
ef.SaveXls(fs);
WebClient client = new WebClient();
client.DownloadFile("http://localhost:58294/Upload.ashx", "ManualEntry");
}
handler upload.ashx
[System.Web.Services.WebMethod(EnableSession = true)]
public void ProcessRequest(HttpContext context)
{
try
{
HttpPostedFile postedFile = context.Request.Files["Filedata"];
string fileName = "ManualEntry.XLS";
string savepath = "";
string tempPath = "";
tempPath = System.Configuration.ConfigurationManager.AppSettings["ManualExcel"];
savepath = context.Server.MapPath(tempPath);
context.Response.ContentType = "application/ms-excel";
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + "ManualEntry");
context.Response.WriteFile(savepath + fileName);
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch (Exception ex)
{
throw ex;
}
}
Please help me
Reply
Answers (
4
)
'System.InvalidCastException'
Using RESTful api in ASP.NET MVC