Method 1:
Copy codeThe Code is as follows:
Response. ClearContent ();
Response. ClearHeaders ();
Response. ContentType = "Application/msword ";
String s = Server. MapPath ("c# .doc ");
Response. WriteFile ("c# .doc ");
Response. Write (s );
Response. Flush ();
Response. Close ();
Method 2:
Copy codeThe Code is as follows:
Response. ClearContent ();
Response. ClearHeaders ();
Response. ContentType = "Application/msword ";
String strFilePath = "";
StrFilePath = Server. MapPath ("c# .doc ");
FileStream fs = new FileStream (strFilePath, FileMode. OpenOrCreate, FileAccess. Read );
Response. WriteFile (strFilePath, 0, fs. Length );
Fs. Close ();
Method 3:
Copy codeThe Code is as follows:
String path = Server. MapPath ("c# .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=file name .doc ");
Response. Flush ();
Response. BinaryWrite (filedata );
Response. End ();