The first method:
Copy Code code as follows:
Response.clearcontent ();
Response.ClearHeaders ();
Response.ContentType = "Application/msword";
String S=server.mappath ("C # Language Reference. doc");
Response.WriteFile ("C # Language Reference. doc");
Response.Write (s);
Response.Flush ();
Response.close ();
The second method:
Copy Code code as follows:
Response.clearcontent ();
Response.ClearHeaders ();
Response.ContentType = "Application/msword";
String Strfilepath= "";
strFilePath =server.mappath ("C # Language Reference. doc");
FileStream fs = new FileStream (strfilepath,filemode.openorcreate,fileaccess.read);
Response.WriteFile (Strfilepath,0,fs. Length);
Fs. Close ();
The third method:
Copy Code code as follows:
String Path=server.mappath ("C # Language Reference. doc");
FileInfo file=new FileInfo (path);
FileStream myfilestream=new FileStream (path,filemode.open,fileaccess.read);
Byte[] Filedata=new byte[file. Length];
Myfilestream.read (filedata,0, (int) (file. Length));
Myfilestream.close ();
Response.Clear ();
Response.contenttype= "Application/msword";
Response.AddHeader ("Content-disposition", "attachment;filename= filename. doc");
Response.Flush ();
Response.BinaryWrite (Filedata);
Response.End ();