#region 檔案操作 /// <summary> /// 讀取記事本 /// </summary> /// <param name="file_model"></param> /// <returns></returns> private HotLine12345.Model.KL_CONTENT_INFO Read_Txt(HotLine12345.Model.KL_FILE file_model) { HotLine12345.Model.KL_CONTENT_INFO model = new HotLine12345.Model.KL_CONTENT_INFO(); model.KL_CONTENT_ID = Convert.ToInt32(file_model.KL_ID); model.KL_CONTENT_TITLE = file_model.File_Name; model.KL_FILE = file_model.ID.ToString(); #region 讀取記事本 string inforContent = ""; string FilePath = Server.MapPath(file_model.File_Path); FileInfo file = new FileInfo(FilePath); if (file.Exists) { try { FileStream stream = new FileStream(FilePath, FileMode.Open); StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("gb2312"));//Encoding.GetEncoding("gb2312"),Encoding.UTF8 //reader.ReadLine(); //一次性讀取一行 inforContent = reader.ReadToEnd(); //一次性讀取全部資料 reader.Close(); stream.Close(); } catch (Exception ce) { throw ce; } } #endregion model.KL_CONTENT = inforContent; return model; } /// <summary> /// 讀取word文檔 /// </summary> /// <param name="file_model"></param> /// <returns></returns> private HotLine12345.Model.KL_CONTENT_INFO Read_Word(HotLine12345.Model.KL_FILE file_model) { HotLine12345.Model.KL_CONTENT_INFO model = new HotLine12345.Model.KL_CONTENT_INFO(); model.KL_CONTENT_ID = Convert.ToInt32(file_model.KL_ID); model.KL_CONTENT_TITLE = file_model.File_Name; model.KL_FILE = file_model.ID.ToString(); #region 讀取word文檔 string inforContent = ""; string FilePath = Server.MapPath(file_model.File_Path); FileInfo file = new FileInfo(FilePath); if (file.Exists) { try { Word.Application app = new Microsoft.Office.Interop.Word.Application(); Word.Document doc = null; object unknow = Type.Missing; app.Visible = false; app.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; object file2 = FilePath; doc = app.Documents.Open(ref file2, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow, ref unknow); inforContent = doc.Content.Text; //關閉檔案 doc.Close(ref unknow, ref unknow, ref unknow); //關閉COM app.Quit(ref unknow, ref unknow, ref unknow); } catch (Exception ce) { throw ce; } } #endregion model.KL_CONTENT = inforContent; return model; } /// <summary> /// 讀取PDF內容 /// </summary> /// <param name="file_model"></param> /// <returns></returns> private HotLine12345.Model.KL_CONTENT_INFO Read_PDF(HotLine12345.Model.KL_FILE file_model) { HotLine12345.Model.KL_CONTENT_INFO model = new HotLine12345.Model.KL_CONTENT_INFO(); model.KL_CONTENT_ID = Convert.ToInt32(file_model.KL_ID); model.KL_CONTENT_TITLE = file_model.File_Name; model.KL_FILE = file_model.ID.ToString(); #region 讀取PDF內容 string inforContent = ""; string FilePath = Server.MapPath(file_model.File_Path); string txtPath = IndexDic + "\\" + Path.GetFileNameWithoutExtension(FilePath) + ".txt"; FileInfo file = new FileInfo(FilePath); if (file.Exists) { try { PDDocument doc = PDDocument.load(FilePath); PDFTextStripper pdfStripper = new PDFTextStripper(); inforContent = pdfStripper.getText(doc); doc.close(); // } catch (Exception ce) { throw ce; } } #endregion model.KL_CONTENT = inforContent; return model; } #endregion
<span style="color:#cc0000;background-color: rgb(255, 255, 255);">pdf請下載相關組件PDFBox-0.7.3.dllIKVM.Runtime.dllIKVM.GNU.Classpath.dllFontBox-0.1.0-dev.dll</span>