I am developing a webpage in that the user can download their Resume for Edit. So I have a link to download the article. I use the following code for download.
DataTable dt = user.getUserDetails(2);
user.WriteFileFromDBbyUserArticleID(Server.MapPath(Convert.ToString(dt.Rows[0].ItemArray[0])), Convert.ToInt32(2), "CV");
FileUtil.writeFileToResponse(Server.MapPath(Convert.ToString(dt.Rows[0].ItemArray[0])), Response);
////////////////////////////////////////////////
public void WriteFileFromDBbyUserArticleID(string FilePath, int UserID, string FileType)
{
DataAccessLayer dal = new DataAccessLayer();
string selectQuery = "Select Articles.Users_WriteFileFromDB(?,?,? ) from Articles.Users";
DbParameter[] parm = new DbParameter[3];
parm[0] = dal.GetParameter();
parm[0].ParameterName = "@FilePath";
parm[0].Value = FilePath;
parm[1] = dal.GetParameter();
parm[1].ParameterName = "@UserID";
parm[1].Value = UserID;
parm[2] = dal.GetParameter();
parm[2].ParameterName = "@FileType";
parm[2].Value = FileType;
DataTable dtArticleStatus = dal.ExecuteDataTable(selectQuery, parm);
}
///////////////////////////////////////////////////////////////////////////
static public void writeFileToResponse(string filePath,HttpResponse Response)
{
try
{
string FileName = Path.GetFileName(filePath);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
Response.WriteFile(filePath);
Response.Flush();
File.Delete(filePath);
Response.End();
}
catch (System.Exception ex)
{
}
}
I got the error in the line "Response.WriteFile(filePath);" as follows
sys.webforms.pagerequestManagerparserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to response.write(), response filters, httpModules, or server trace is enabled. Details:Error parsing near ...
How do I fix this?