#region file operations
/// <summary>
/// read notepad
/// </ 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 read notepad
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 (); // Read one line at a time
inforContent = reader.ReadToEnd (); // Read all data at once
reader.Close ();
stream.Close ();
}
catch (Exception ce)
{
throw ce;
}
}
#endregion
model.KL_CONTENT = inforContent;
return model;
}
/// <summary>
/// read word document
/// </ 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 Reading word documents
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;
// Close the file
doc.Close (ref unknow, ref unknow, ref unknow);
// Close COM
app.Quit (ref unknow, ref unknow, ref unknow);
}
catch (Exception ce)
{
throw ce;
}
}
#endregion
model.KL_CONTENT = inforContent;
return model;
}
/// <summary>
/// read PDF content
/// </ 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 Reading PDF content
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 Please download the relevant components
PDFBox-0.7.3.dll
IKVM.Runtime.dll
IKVM.GNU.Classpath.dll
FontBox-0.1.0-dev.dll </ span>