I used Asp.net yesterday to directly save the file to the client. After repeated tests, all kinds of documents run completely normally. So we modified the existingCode, Modified the Download Method to Solve the window interception problem that has been plagued by yourself.
I was complacent in the morning, so I don't need to explain to the customer why the window is gone. Unfortunately, it is not as good as daily calculation, but MS has overcast it.
In the morning, the customer reported that all downloaded files were garbled. Test on the local machine immediately. OK, no problem. If you don't believe this, it's okay to try it on a colleague's machine.
#¥ # ¥ % ...... # ¥ % ...... ¥ % ...... -¥ # ¥ % ...... # ¥ % ......
I am dizzy, it should be the client problem. We had to ask the customer netmeeting to demonstrate her operation process. Download-> Save-> open. Even idiots will not do anything wrong with such a simple process?
Oh, my God, Ms. ### $ % ^ $ # % & ^ & % ^
When I was depressed, my mind suddenly flashed and finally found something different. I tried it right away! Speaking of this, I really want to # @ # $ Microsoft...
What is the difference? See the operation diagram:
Guest operation diagram
My operation diagram
Should you see the difference? If you still can't see it, it's about pp. --- pai_^
The culprit of this incident is:
Solution: How to Use lovecherry to read the file contenttype from the Registry
Corrected code:
1 /**/ /// <Summary>
2 /// Download files
3 /// </Summary>
4 /// <Param name = "FILENAME"> Physical file address </Param>
5 Protected Void Downloadfile ( String Filename)
6 {
7
8 String Savefilename = " Test.xls " ;
9 Int Intstart = Filename. lastindexof ( " \\ " ) + 1 ;
10 Savefilename = Filename. substring (intstart, filename. Length - Intstart );
11
12 System. Io. fileinfo fi = New System. Io. fileinfo (filename );
13 String Fileextname = Fi. extension;
14 String Default_content_type = " Application/unknown " ;
15 Registrykey regkey, fileextkey;
16 String Filecontenttype;
17 Try
18 {
19 Regkey = Registry. classesroot;
20 Fileextkey = Regkey. opensubkey (fileextname );
21 Filecontenttype = Fileextkey. getvalue ( " Content type " , Default_content_type). tostring ();
22 }
23 Catch
24 {
25Filecontenttype=Default_content_type;
26}
27
28
29 Response. Clear ();
30 Response. charset = " UTF-8 " ;
31 Response. Buffer = True ;
32 This . Enableviewstate = False ;
33 Response. contentencoding = System. Text. encoding. utf8;
34
35 Response. appendheader ( " Content-Disposition " , " Attachment; filename = " + Savefilename );
36 Response. contenttype = Filecontenttype;
37
38 Response. writefile (filename );
39 Response. Flush ();
40 Response. Close ();
41
42 Response. End ();
43 }
44
Finally, it is concluded that there is a way to directly display the file to the browser (response) without considering the file type, so that the client does not hide the known extension, however, this method cannot adapt to most computer users (generally, only those familiar with computers will do this, right? Guest, forget it... at that time ------- failed READING)