1. Function description
Input file path, in the browser output file preview information, tested 360 speed (Chrome), IE9/10, Firefox through
2. Classification file and code description
Demofiles to store testable files
Default.aspx startup page
ExcelPreview.cs Excel Preview Class
public static void Priview (System.Web.UI.Page p, string infilepath, String outdirpath = "") {Microsoft.Office.Inte Rop.
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, missing, missing, missing, missing, missing, MI
Ssing, missing, missing, missing, missing, 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, missing, missing, missing, XlsaveasAccessmode.xlnochange, missing, missing, missing, missing, missing); Excel.
Quit ();
Open generated Html Process process = new process (); Process.
Startinfo.useshellexecute = true; Process.
Startinfo.filename = outputfile; Process.
Start (); }
4.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 ();
}
5.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 encoding format consistent with the file
p.response.addheader ("Content-disposition", "filename=" + filename);
P.response.writefile (Infilepath);
P.response.end ();
}
6. WordPreview.cs Word Preview class
7.readme.txt describes basic functionality and methods for referencing COM components (you first need to install Office), and the components to be introduced include
Microsoft Word 15.0
Microsoft Excel 15.0
Preview effect
1, Word
2, Excel
3, PDF
4, TXT
Unresolved issues
PDF, TXT file can only be displayed on the current page, and cause the back key is invalid, please help solve the two files and doc, xls like in the new tab open
5. SOURCE Download
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!