I try to export information to CSV but when i open the CSV it contains the CSV elements and complete page. Does anybody know wat could be the problem?:
The control contains:
<asp:LinkButton ID="lnkExport" runat="server" Text="Export" CssClass="dnnPrimaryAction" OnClick="lnkExport_Click" />
The lnkExport_Click code contains:
protected void lnkExport_Click(object sender, EventArgs e)
{
try
{
int ReportID = 1;
ImportReportInfo report = ImportReportController.Get(this.PortalId, ReportID);
if (report != null)
{
ArrayList importedUsers = ImportedUserController.ListByReportID(this.PortalId, ReportID);
string ResultString = "";
foreach (ImportedUserInfo user in importedUsers)
{
ResultString += user.Username + "," + user.Firstname + "," + user.Lastname + "," + user.Street + "," + user.City + "," + user.Country + "," + user.Email + "," + user.ImportStatus + "," + user.ImportDate + "," + Environment.NewLine;
}
string fileName = String.Format("import report-{0}.csv", report.ReportDate.ToString("yyyy-MMM-dd-HHmmss"));
System.Web.HttpResponse Response = System.Web.HttpContext.Current.Response;
byte[] lstByte = System.Text.Encoding.UTF8.GetBytes(Result);
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = string.Format("{0}; charset=utf-8", ContentType);
Response.AppendHeader("Content-disposition", string.Format("attachment; filename=\"{0}\"", FileName));
Response.AppendHeader("Content-Length", lstByte.Length.ToString());
Response.BinaryWrite(lstByte);
Response.Flush();
Response.End();
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}