Assign a value to XLS via HTML and download the XLS file
First, this. Response.Write (SW. ToString ()); System.IO.StringWriter sw = new System.IO.StringWriter ();
this. Response.Clear ();
string strFileName;
strFileName = "report" + ". xls";
Response.Buffer = true;
Response.ContentType = "application/ X-zip-compressed ";
Response.AddHeader ("Accept-language", " ZH-CN ");
Response.AddHeader ("Content-disposition" , "Attachment;filename=" + HttpContext.Current.Server.UrlEncode (strFileName));
System.IO.StringWriter SW = new System.IO.StringWriter ();
System.Web.UI.HtmlTextWriter htmlwrite = New HtmlTextWriter (SW);
this.gvMutiQueResult.AllowPaging = false;
if (session["QueryResult"]! = NULL)
{
This.gvMutiQueResult.DataSource = (DataTable) session[" QueryResult "];
This.gvMutiQueResult.DataBind ();
}
Else
{
BINDGV (); Bind data
}
This.gvMutiQueResult.RenderControl (Htmlwrite);
This . Response.Write (SW. ToString ());
This. Response.End ();
Response.Write ("<script type= ' Text/javascript ' >window.history.back ();</script>");
Second,Response.Write (html2excel); string html2excel
String strhtml; String FileName;
Response.Clear ();
Response.AddHeader ("Content-disposition", "attachment;filename=\" "+ httputility.urlencode (filename) +". Xls\ "");
Response.ContentType = "Application/ms-excel";
String html2excel = "+
String. Format (@ "<!--[if GTE MSO 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>{0}</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:validprinterinfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
<! [endif]--> ", FileName)
+ "+ strHTML +
"</body>
Response.Write (html2excel);
Response.End ();
Three
//Get Data
Idatabase SDB = Dbfactory.getdbinstance ();
DataTable dt = Sdb.getdatatable ("SELECT * from table where id= '" + ID.) ToString () + "'");
//Output
if (dt. Rows.Count > 0)
{
String docfilename = dt. rows[0]["Docfilename"]. ToString ();
String docsize = dt. rows[0]["DocSize"]. ToString ();
byte[] doccontent = (byte[]) dt. rows[0]["Doccontent"];
Response.Clear ();
Response.ClearHeaders ();
Response.Buffer = false;
String ContentType = dt. rows[0]["DocType"]. ToString ();
Response.ContentType = "Application/octet-stream";
Response.AddHeader ("Content-disposition", "attachment; Filename=\ "" + Httputility.urlencode (Docfilename, System.Text.Encoding.UTF8) + "\" ");
Response.AddHeader ("Content-length", docsize.tostring ());
Response.BinaryWrite (doccontent);
Response.Flush ();
Response.End ();
}
Iv.Response.WriteFile (downloadfile.fullname); System.IO.FileInfo DownloadFile = new System.IO.FileInfo (strFileName);
Download Boot reminder installer rar
private void Downloaddocument ()
{
Try
{
String strFileName = Server.MapPath (".. /.. /help/bootalert.rar ");
System.IO.FileInfo DownloadFile = new System.IO.FileInfo (strFileName);
Response.Clear ();
Response.ClearHeaders ();
Response.Buffer = false;
Response.ContentType = "Application/ms-excel";
Response.appendheader ("Content-disposition", "attachment;filename=" + httputility.urlencode (StrFileName, SYSTEM.TEXT.ENCODING.UTF8));
Response.appendheader ("Content-length", DownloadFile.Length.ToString ());
Response.WriteFile (downloadfile.fullname);
Response.Flush ();
Response.End ();
}
catch (Exception err)
{
throw err;
}
}
V. byte[] binarycontent response.binarywrite (binarycontent);
NewFileName = Newfilename.replace ("\\\\", "\ \"). Replace ("\ \", "/");
String outputfilename = newfilename.substring (Newfilename.lastindexof ('/') + 1);
byte[] binarycontent = System.IO.File.ReadAllBytes (NewFileName);
Response.Clear ();
Response.ClearHeaders ();
Response.Buffer = false;
Response.ContentType = "Application/octet-stream";
Response.AddHeader ("Content-disposition", "attachment; Filename=\ "" + Httputility.urlencode (OutputFileName, System.Text.Encoding.UTF8) + "\" ");
Response.AddHeader ("Content-length", Binarycontent.count (). ToString ());
Response.BinaryWrite (binarycontent);
Response.Flush ();
Response.End ();
Six,response.transmitfile (strFilePath, 0, fileSize); long fileSize = info. Length
FileInfo info = new FileInfo (strFilePath);
Long fileSize = info. Length;
Response.Clear ();
Response.Buffer = true;
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader ("Accept-language", "ZH-CN");
Response.AddHeader ("Content-disposition", "attachment;filename=" + HttpContext.Current.Server.UrlEncode (info. Name));
Does not indicate that content-length with flush will not show download progress
Response.AddHeader ("Content-length", filesize.tostring ());
response.transmitfile (strFilePath, 0, fileSize);
Response.Flush ();
Response.close ();
Info. Delete ();