ASP tutorial. NET import Excel or Word document code
Description of the use of enableeventvalidation= "false";
When you add an input server control (such as a TextBox) to a page, you need to set to false, or you will get an error, which is to turn off page validation, which is turned on by default.
private void Dbexport ()
{
Httpcontext.current.response.charset = "gb2312";
httpcontext.current.response.contentencoding = Encoding.UTF8;
Some articles in the use of UTF7, is because in special circumstances Chinese will appear garbled; Here it is recommended to use utf8,msdn mentioned Utf7 no UTF8 high security;
The following two lines are guaranteed to be correct, using the method shown in the code
Response.Write ("Response.Write ("</body>Here the file name is encoded to prevent the occurrence of Chinese name garbled phenomenon
Httpcontext.current.response.appendheader ("Content-disposition", "attachment;filename=" + Httputility.urlencode) (" File name. xls ", Encoding.UTF8));
Export Excel format, because the format is different, so the file name suffix should be adjusted according to the actual situation (. xls)
Httpcontext.current.response.contenttype = "Vnd.ms-excel";
Export Word format, because the format is different, so the file name suffix should be adjusted according to the actual situation (. doc)
Httpcontext.current.response.contenttype = "Vnd.ms-word";
Export HTML format, because the format is different, so the file name suffix should be adjusted according to the actual situation (. html)
Httpcontext.current.response.contenttype = "text/html";
There are two kinds of writing seems to be able to directly output the image, did not have time to textual research, but it should not be like the above changes in the format can be, should be the first to create graphics objects can be set Response.ContentType to output
Who has a simple way of wishing to post, study, thank you
Httpcontext.current.response.contenttype = "Image/gif";
Httpcontext.current.response.contenttype = "Image/jpeg";
Explain what the next divid is, here should be the control you want to turn out, can be the server control can also HTML control (to add runat= "server" otherwise this is not found in the control)
My page is a div id= "divid" runat= "Server" with a GridView for displaying data
Divid.page.enableviewstate = false;
System.IO.StringWriter tw = new System.IO.StringWriter ();
HtmlTextWriter HW = new HtmlTextWriter (TW);
Divid.rendercontrol (HW);
The bottom three lines are the output of the data.
Response.Write ("Httpcontext.current.response.write (Tw.tostring ());
Response.Write ("</body>
Response.Flush ();
Response.close ();
}
This method needs to be rewritten or it will be an error
public override void Verifyrenderinginserverform (Control control)
{
}