There are many files on the server. Currently, the following formats are considered:
. Bmp. jpg. gif. Doc. xls. txt. pdf. ppt
I can get the path of these files, which is to display the content of these files on the page. I tested that all images in the format can be written to the browser using response. writefile (filename.
But are all files in other formats garbled? How can this problem be solved?
The Code is as follows:
Protected system. Web. UI. webcontrols. dropdownlist drpfilelist;
Private void page_load (Object sender, system. eventargs E)
{
If (! Ispostback)
{
Drpfilelist. Items. Add ("");
Drpfilelist. Items. Add (@ "D: \ testmm \ pic31673.jpg ");
Drpfilelist. Items. Add (@ "D: \ testmm \ test.txt ");
Drpfilelist. Items. Add (@ "D: \ testmm \ test.doc ");
Drpfilelist. Items. Add (@ "D: \ testmm \ test.xls ");
Drpfilelist. Items. Add (@ "D: \ testmm \ test.ppt ");
Drpfilelist. Items. Add (@ "D: \ testmm \ test.pdf ");
Drpfilelist. selectedindex = 0;
}
}
Private void drpfilelist_selectedindexchanged (Object sender, system. eventargs E)
{
Response. Clear ();
Response. charset = "UTF-8 ";
Response. Buffer = true;
This. enableviewstate = false;
Response. contentencoding = system. Text. encodingl. utf8;
// I wrote inline online when I asked about the inspiration source and Dudu last night!
// Some online examples are wrong, such as http://www.knowsky.com/list.asp? Id = 4870
Response. appendheader ("content-disposition", "inline; filename =" + drpfilelist. selecteditem. Text );
Response. writefile (drpfilelist. selecteditem. Text );
Response. End ();
}
I asked Dudu the source of inspiration last night. I haven't solved it yet!
I was wondering, if all files in any format are displayed, can this requirement be met?
It's a little strange if it doesn't work either?