I created a dynamic form site like Google Form, one of the requirements is that on each survey I could attach a Word file that should be printed after I print the survey form.
So, after I download the file from the database what do I have to do to print it?
Example code:
private void downloadFile()
{
string item = Request.Form["__EVENTARGUMENT"].ToString();
SQL sql_files = new SQL(ConnectionStringName.FilesSqlServer);
sql_files.ExecuteStoreProcedure(SqlStoreProcedureNames.spFileStorage, SqlOutputType.DataReader, new SQLParameter[]{
new SQLParameter(ParameterDirection.Input, SqlDbType.VarChar, "@IdRespuesta", Session["id_respuesta"].ToString()),
new SQLParameter(ParameterDirection.Input, SqlDbType.VarChar, "@ItemID", item),
new SQLParameter(ParameterDirection.Output, SqlDbType.VarChar, "@SpError")
});
if (sql_files.Reader.HasRows)
{
sql_files.Reader.Read();
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + sql_files.Reader["name"].ToString());
Response.ContentType = sql_files.Reader["contenttype"].ToString();
byte[] fileBytes = (byte[])sql_files.Reader["bytes"];
Response.AddHeader("Content-Length", fileBytes.Length.ToString());
Response.BinaryWrite(fileBytes);
Response.Flush();
Response.End();
}
sql_files.Reader.Close();
}
I use this code to download the file, so I need to change it so I can print a Word document.
Greetings,
Clark
Your current code downloads a file to a client machine. You cannot control the printing. It all depends on client. Do you actually want to print it on a printer or you mean something different?
Edit:
There’s no way to show printing dialog to a user, since it is browser specific.
One thing you can try is to use
--kioskand--kiosk-printingprefixes for Chrome 18+.Note that you cannot run any code after Response.End() without causing a request from a user. if you want to run any code after Response.End() you will have to use IFrame or WebHandler.