file download problem
-
hi, i am using following code to download file from application its working fine in local system but when i configure in server a file is opening with sourse of aspx page can any one help me ? string FilePath = Globals.ApplicationVRoot + "/Downloads/DemoUser.CSV"; string FileName = "DemoUser.CSV"; HttpResponse response = HttpContext.Current.Response; response.ContentType = "application/octet-stream"; response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); response.WriteFile(FilePath.ToString()); response.End();
-
hi, i am using following code to download file from application its working fine in local system but when i configure in server a file is opening with sourse of aspx page can any one help me ? string FilePath = Globals.ApplicationVRoot + "/Downloads/DemoUser.CSV"; string FileName = "DemoUser.CSV"; HttpResponse response = HttpContext.Current.Response; response.ContentType = "application/octet-stream"; response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); response.WriteFile(FilePath.ToString()); response.End();
You should write following code: string FilePath = Globals.ApplicationVRoot + "/Downloads/DemoUser.CSV"; byte []b=System.IO.File.ReadAllBytes(FilePath); string FileName = "DemoUser.CSV"; HttpResponse response = HttpContext.Current.Response; response.ClearHeaders(); response.ClearContent(); response.ContentType = "application/octet-stream"; response.AddHeader("Content-Length",b.Length.ToString()); response.AddHeader("Content-Disposition", "attachment; filename=" + FileName); response.BinaryWrite(b); response.Flush(); response.End();
A DATAPOST COMPUTER CENTRE (K.V Prajapati)