Function Description: Enter the file path and output the file preview information in the browser. It is tested to be (Chrome), IE9/10, and Firefox stores the file Default by using the classification file and code description DemoFiles. aspx startup page ExcelPreview. cs Excel preview class public static void Priview (System. web. UI. page p, string inFilePath, string outDirPath = "") {Microsoft. office. interop. excel. application excel = null; Microsoft. office. interop. excel. workbook xls = null; excel = new Microsoft. office. interop. excel. application (); object missing = Type. missing; object trueObject = true; excel. visible = false; excel. displayAlerts = false; string randomName = DateTime. now. ticks. toString (); // output fileName xls = excel. workbooks. open (inFilePath, missing, trueObject, missing, and missing ); // Save Excel to Html object format = Microsoft. office. interop. excel. xlFileFormat. xlHtml; Workbook wsCurrent = xls; // (Workbook) wsEnumerator. current; String outputFile = outDirPath + randomName + ". html "; wsCurrent. saveAs (outputFile, format, missing, XlSaveAsAccessMode. xlNoChange, missing, missing); excel. quit (); // Open generated Html Process process = new Process (); process. startInfo. useShellExecute = true; process. startInfo. fileName = outputFile; process. start ();} PDfPreview. cs Pdf preview class public static void Priview (System. web. UI. page p, string inFilePath) {p. response. contentType = "Application/pdf"; string fileName = inFilePath. substring (inFilePath. lastIndexOf ('\') + 1); p. response. addHeader ("content-disposition", "filename =" + fileName); p. response. writeFile (inFilePath); p. response. end ();} TextFilePreview. cs text file Preview class public static void Preview (System. web. UI. page p, string inFilePath) {string fileName = inFilePath. substring (inFilePath. lastIndexOf ('\') + 1); p. response. contentType = "text/plain"; p. response. contentEncoding = System. text. encoding. UTF8; // keep the same encoding format as the file p. response. addHeader ("content-disposition", "filename =" + fileName); p. response. writeFile (inFilePath); p. response. end ();} WordPreview. cs Word Preview