Can you directly display the file to the browser (response) regardless of the file type)

Source: Internet
Author: User

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?

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.