Note that there are some explanatory texts on larger screens.

plurals
  1. POResponse.WriteFile writing the content twice
    primarykey
    data
    text
    <p>Here is my code..</p> <pre><code> string attachment = "attachment; filename=Call-Details-Report-" + startDate.SelectedDate.Value.ToString("MM-dd-yyyy") + ".csv"; Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("Content-Disposition", attachment); Response.ContentType = "text/csv"; Response.AddHeader("Pragma", "public"); Response.WriteFile(downloadLocation+"\\"+fileName); Response.End(); </code></pre> <p>I'm using the above code to download a csv file from a location.But surprisingly the contents gets written twice or some times thrice into the file that i download though actually it isn't so with the file on server.I'm writing my code in c#. The above piece of code works perfectly in local machine,but the issue is in Production server.</p> <p>Here is my complete Method</p> <pre><code> private void DownloadReport(string query) { string downloadFolderPath = ""; string filePath = ""; string dbAndApplicationServerStatus = ConfigurationManager.AppSettings["SameDBAndApplicationServer"] != null ? ConfigurationManager.AppSettings["SameDBAndApplicationServer"] : "1"; if (dbAndApplicationServerStatus == "0") { Log.Write("So the DB And Application are on differrent servers,hence trying to read Download folder path on DB Server...."); downloadFolderPath = ConfigurationManager.AppSettings["ReportDownloadLocation"] != null ? ConfigurationManager.AppSettings["ReportDownloadLocation"] : "-1"; Log.Write("Download Path is " + downloadFolderPath); } else { Log.Write("So the DB and Application and Db are on same server......"); downloadFolderPath = Server.MapPath("Download"); downloadFolderPath = downloadFolderPath.Replace("\\", "//"); if (!Directory.Exists(downloadFolderPath)) { Directory.CreateDirectory(downloadFolderPath); } Log.Write("Download Path is " + downloadFolderPath); } string status=""; StringBuilder headerQuery = new StringBuilder(); StringBuilder rowQuery = new StringBuilder(); StringBuilder sqlQuery = new StringBuilder(); filePath = downloadFolderPath; string folderName = DateTime.Now.ToString("MM-dd-yyyy"); string timeStamp = DateTime.Now.ToString("MM-dd-yy-HH-mm-ss"); string fileName = "Call-Details-Report-" + startDate.SelectedDate.Value.ToString("MM-dd-yyyy") + "_" + timeStamp + ".csv"; filePath = filePath + "/" + fileName; bool commaRequired = false; sqlQuery.Append("SELECT * INTO OUTFILE '"); sqlQuery.Append(filePath); sqlQuery.Append("' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' FROM ("); headerQuery.Append("Select "); rowQuery.Append("(Select "); #region Creating Query /*Sql Query is Created in this region*/ #endregion if (!CdrSearch.WriteReportToFile(sqlQuery.ToString(),out status)) { Log.Write("Failed to generate the file to download......"); WebPagesHelper.ShowMessage(ref lblMessage, WebPagesHelper.MessageType.Message, status); } else { Log.Write("Succesfully generated file to Download"); string downloadLocation = Server.MapPath("Download"); if (dbAndApplicationServerStatus == "0") { WebClient webClient = new WebClient(); string path = ConfigurationManager.AppSettings["DownloadURL"] != null ? ConfigurationManager.AppSettings["DownloadURL"].ToString() : ""; if (!Directory.Exists(downloadLocation)) { Directory.CreateDirectory(downloadLocation); } if (File.Exists(downloadLocation + "\\" + fileName)) { File.Delete(downloadLocation + "\\" + fileName); } webClient.DownloadFile(path + fileName, downloadLocation + "\\" + fileName); } Log.Write("Configured Download Location on Application" + downloadLocation); string attachment = "attachment; filename=Call-Details-Report-" + startDate.SelectedDate.Value.ToString("MM-dd-yyyy") + ".csv"; Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("Content-Disposition", attachment); Response.ContentType = "text/csv"; Response.AddHeader("Pragma", "public"); Log.Write(downloadLocation + "\\" + fileName); Response.WriteFile(downloadLocation+"\\"+fileName); Response.SetCookie(new HttpCookie("DStatus", "Completed")); Response.End(); } } </code></pre> <p>And the above method is called only once straight away on click of a button,so no question of any looping here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload