public string GetTextByCommandLine(string pdfFileName) { string pdf2TextPath = Path.Combine(DirectoryHelper.CurrentExeDirectory, "ThirdParty", "pdftotext.exe"); string outfilePath = pdfFileName.Replace(".pdf", ".txt"); var process = new Process { StartInfo = new ProcessStartInfo { FileName = pdf2TextPath, Arguments = pdfFileName.AddQuotes() + " " + outfilePath.AddQuotes(), WindowStyle = ProcessWindowStyle.Hidden } }; process.Start(); process.WaitForExit(); FileInfo txtFile = new FileInfo(outfilePath); string content = txtFile.Read(); //File.Delete(txtFile.FullName); return content; }
/// <summary> /// Compares two files against one another /// </summary> /// <param name="File1">First file</param> /// <param name="File2">Second file</param> /// <returns>True if the content is the same, false otherwise</returns> public static bool CompareTo(this FileInfo File1, FileInfo File2) { Contract.Requires<ArgumentNullException>(File1 != null && File1.Exists, "File1"); Contract.Requires<ArgumentNullException>(File2 != null && File2.Exists, "File2"); if (File1.Length != File2.Length) return false; return File1.Read().Equals(File2.Read()); }
/// <summary> /// Gets the addressess. /// </summary> /// <returns></returns> public static AddressDTOCollection GetAddressess() { var fi = new FileInfo(AddressFilePath); if (fi.Exists) { var xml = fi.Read(); return xml.Deserialize<AddressDTOCollection>(); } return null; }
/// <summary> /// Compares two files against one another /// </summary> /// <param name="file1">First file</param> /// <param name="file2">Second file</param> /// <returns>True if the content is the same, false otherwise</returns> public static bool CompareTo(this FileInfo file1, FileInfo file2) { if (file1 == null || !file1.Exists) throw new ArgumentNullException("file1"); if (file2 == null || !file2.Exists) throw new ArgumentNullException("file2"); if (file1.Length != file2.Length) return false; return file1.Read().Equals(file2.Read()); }
/// <summary> /// 根据路径得到文件流 /// </summary> /// <param name="strFilePath"></param> /// <param name="strValue"></param> public static byte[] GetFileSream(string Path) { byte[] buffer = null; using (FileStream stream = new System.IO.FileInfo(Path).OpenRead()) { buffer = new byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); } return(buffer); }
/// <summary> /// 将文件转换成二进制 /// </summary> /// <returns></returns> public static byte[] FileToBinary(string fullName) { try { System.IO.FileStream stream = new System.IO.FileInfo(fullName).OpenRead(); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); return(buffer); } catch (Exception ex) { throw new Exception(ex.Message); } }
static StringPinyinExtensionMethods() { FileInfo file = new FileInfo(DirectoryHelper.CombineWithCurrentExeDir("pingyin_extension.txt")); string content = file.Read(); var lines = content.ToLines(); foreach (var item in lines) { var array = item.Split(','); if (array.Length == 2) specailList.Add(array[0][0], array[1]); } }
private string Contents() { string _contents = ""; if (IsIniFile()) { if (String.IsNullOrEmpty(_contents.RLTrim())) { FileInfo _file = new FileInfo(_filename); _contents = _file.Read(); } } return _contents; }
/// <summary> /// 将文件转换成二进制 /// </summary> /// <returns></returns> public static byte[] ConvertToBinaryByPath(string path) { try { System.IO.FileStream stream = new System.IO.FileInfo(path).OpenRead(); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); return(buffer); } catch (Exception E) { throw E; //return null; } }
internal static void FileStreamTest() { Console.WriteLine("文件流读写测试:\n"); //不同的方式打开文件流 FileStream testFile = new FileStream("test.txt", FileMode.Create, FileAccess.ReadWrite); //FileStream testFile2 = new FileInfo("text2.txt").Open(FileMode.OpenOrCreate, FileAccess.ReadWrite); //写文件 testFile.WriteByte(50); testFile.Write(new byte[] { 10, 20, 30, 40 }, 0, 4); testFile.Close(); //读文件 testFile = new FileInfo("test.txt").OpenRead(); byte[] buffer = new byte[testFile.Length]; testFile.Read(buffer, 0, buffer.Length); new List<byte>(buffer).ForEach((e) => Console.Write(e)); Console.WriteLine(); testFile.Close(); }
public string GiveMeAJoke() { if (lines == null) { FileInfo fileInfo = new FileInfo(DirectoryHelper.CombineWithCurrentExeDir("joke.txt")); lines = fileInfo.Read().ToLines(); } jokeIndex = status.Get("joke_index","0").StrToInt() + 1; if (jokeIndex >= lines.Length) jokeIndex = 0; status.AddOrUpdate("joke_index", jokeIndex.ToString()); status.SaveToFile(); return lines[jokeIndex]; }
private static void SetupDependencies() { foreach (FileInfo File in new DirectoryInfo("..\\..\\..\\BatmanPackages\\").EnumerateFiles("*.nuspec", SearchOption.AllDirectories)) { FileInfo PackagesFile = new FileInfo("..\\..\\..\\" + File.Name.Replace(".nuspec", "") + "\\packages.config"); if (PackagesFile.Exists) { string PackagesContent = PackagesFile.Read(); string FileContent = File.Read(); foreach (Match Package in Regex.Matches(PackagesContent, @"<package id=""(?<Package>[^""]*)"" version=""(?<Version>[^""]*)""")) { if (Regex.IsMatch(FileContent, @"<dependency id=""" + Package.Groups["Package"].Value + @""" version=""(?<VersionNumber>[^""]*)"" />")) { Match TempMatch = Regex.Match(FileContent, @"<dependency id=""" + Package.Groups["Package"].Value + @""" version=""(?<VersionNumber>[^""]*)"" />"); FileContent = FileContent.Replace(TempMatch.Value, @"<dependency id=""" + Package.Groups["Package"].Value + @""" version=""[" + Package.Groups["Version"].Value + @"]"" />"); } } File.Save(FileContent); } } }
/// <summary> /// @Autor:Robin /// @Date:2015-08-19 /// @Desc:根据指定路径获取文件流 /// </summary> /// <param name="filePath">文件路径</param> /// <returns>文件流</returns> public static byte[] GetFileSream(string filePath) { try { byte[] buffer = null; using (FileStream stream = new FileInfo(filePath).OpenRead()) { buffer = new byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); } return buffer; } catch (IOException ex) { throw ex; } }
private void InitializedContentsFromDataSource(DataTable table) { if (table != null) { ClearContents(); string _temppath = Application.StartupPath + "\\tempdatasource.xml"; try { table.WriteXml(_temppath, XmlWriteMode.WriteSchema); } catch { } if (File.Exists(_temppath)) { FileInfo _file = new FileInfo(_temppath); try { _contents.Append(_file.Read()); } catch { } finally { try { File.Delete(_temppath); } catch { } } } } }
/// <summary> /// 根据路径得到文件流 /// </summary> /// <param name="strFilePath"></param> /// <param name="strValue"></param> public static byte[] GetFileSream(string Path) { byte[] buffer = null; using (FileStream stream = new FileInfo(Path).OpenRead()) { buffer = new byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); } return buffer; }
public void SendMail(string title, string content, List<string> emailList, List<string> ccList, MailPriority mailPriority, string AttachmentFilePath,bool IsHTML = false) { if (emailList.Count == 0) return; System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(); foreach (string email in emailList) { if (!string.IsNullOrEmpty(email.Trim())) { msg.To.Add(email); } } msg.From = new MailAddress("*****@*****.**", "Nx-Daigou Luebeck", System.Text.Encoding.UTF8); foreach (var item in ccList) { if (!string.IsNullOrEmpty(item.Trim())) { msg.CC.Add(item); } } msg.Subject = title; msg.SubjectEncoding = System.Text.Encoding.UTF8; msg.Body += content; if (AttachmentFilePath.Length != 0 && File.Exists(AttachmentFilePath)) { msg.Attachments.Add(new Attachment(AttachmentFilePath)); } if (IsHTML) { if (!emailList.Contains("*****@*****.**")) { try { FileInfo htmlAppendix = new FileInfo(DirectoryHelper.CombineWithCurrentExeDir("email_appendix.html")); msg.Body += htmlAppendix.Read(); } catch { } } msg.Body += "<br/><hr/><strong>最后附上一短笑话,祝你天天开心 ‵(*∩_∩*)′ Yeah~~</strong><br/>" + jokeProvider.GiveMeAJoke(); msg.Body += "<br/><hr/><br/><br/><strong>包裹发自 德国 吕贝克 - Luebeck Deutschland 23560 </strong><br/>"; msg.Body += "<a href=\"http://baike.baidu.com/view/206158.htm?fr=aladdin\">德国 吕贝克 百度百科介绍 </a><br/>"; msg.Body += "http://baike.baidu.com/view/206158.htm?fr=aladdin"; } else { msg.Body += "\n \n 最后附上一短笑话,祝你天天开心 ‵(*∩_∩*)′ Yeah~~ \n" + jokeProvider.GiveMeAJoke(); msg.Body += "\n \n德国 吕贝克 "; } msg.BodyEncoding = System.Text.Encoding.UTF8; msg.IsBodyHtml = IsHTML; msg.Priority = mailPriority; var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("*****@*****.**", "980203root"), EnableSsl = true }; client.Send(msg); }
private void AssertFilesBinaryEqual(string expectedFileName, string actualFileName) { int row = 0; FileStream expectedStream = new FileInfo(expectedFileName).Open(FileMode.Open, FileAccess.Read); FileStream actualStream = new FileInfo(actualFileName).Open(FileMode.Open, FileAccess.Read); string failMessage = string.Empty; try { while (!IsEOF(expectedStream) && !IsEOF(actualStream)) { byte[] bufferExpected = new byte[16]; byte[] bufferActual = new byte[16]; expectedStream.Read(bufferExpected, 0, 16); actualStream.Read(bufferActual, 0, 16); int i = 0; for (; i < 16; i++) if (bufferExpected[i] != bufferActual[i]) break; if (i < 16) { int diffPosition = row * 16 + i; failMessage = string.Format("files differ at byte {0}", diffPosition); break; } row++; } if (failMessage == string.Empty) { if (!IsEOF(expectedStream)) Assert.Fail("expected is longer"); else if (!IsEOF(actualStream)) Assert.Fail("actual is longer"); } } finally { expectedStream.Close(); expectedStream.Dispose(); actualStream.Close(); actualStream.Dispose(); } if (failMessage != string.Empty) { Console.WriteLine("AssertBinaryFilesEqual failed expected file {0} actual file {1}: {2}", expectedFileName, actualFileName, failMessage); AssertFailMyXls(failMessage, expectedFileName, actualFileName); } }
/// <summary> /// Compares two files against one another /// </summary> /// <param name="File1">First file</param> /// <param name="File2">Second file</param> /// <returns>True if the content is the same, false otherwise</returns> public static bool CompareTo(this FileInfo File1, FileInfo File2) { if (File1 == null || !File1.Exists) throw new ArgumentNullException("File1"); if (File2 == null || !File2.Exists) throw new ArgumentNullException("File2"); if (File1.Length != File2.Length) return false; if (!File1.Read().Equals(File2.Read())) return false; return true; }
//文件系统 int loadUsers() { try { StreamReader lsr = File.OpenText(".\\users.txt"); int n = 2; int i; //label1.Text = "Find " + n.ToString() + " Users"; for (i = 0; i < n; i++) { string temp = lsr.ReadLine(); userName.Add(temp); int m = Convert.ToInt16(lsr.ReadLine()); int j; for (j = 0; j < m; j++) { string tfilepath = lsr.ReadLine(); FileStream stream = new FileInfo(tfilepath).OpenRead(); Byte[] buffer = new Byte[stream.Length]; //从流中读取字节块并将该数据写入给定缓冲区buffer中 stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); FaceTemplate ftem; ftem.templateData = buffer; faceTemplates.Add(ftem); stream.Close(); } List<FaceTemplate> atemp = new List<FaceTemplate>(faceTemplates.ToArray()); UserTemplates.Add(atemp); faceTemplates.Clear(); } lsr.Close(); Console.WriteLine("Load OK"); Console.WriteLine(UserTemplates.Count.ToString()); Console.WriteLine(userName.Count.ToString()); return 0; } catch { Console.WriteLine("No user Stored"); return 1; } }
/// <summary> /// Executes the specified sql commandtext using MySql application itself. /// </summary> /// <param name="connectionstring">MySql database connection string</param> /// <param name="file">MySql dump file to where the sql statements resides</param> /// <param name="parameters">Additional MySql parameters</param> /// <returns>Development.Materia.Database.MySqlResult that contains the direct MySql application SQL execution information.</returns> public static MySqlResult Execute(string connectionstring, FileInfo file, MySqlParameterCollection parameters) { MySqlResult _result = null; if (file != null) { string _sql = file.Read(); if (!String.IsNullOrEmpty(_sql.RLTrim())) _result = Execute(connectionstring, _sql, parameters); else _result = new MySqlResult(file.FullName, "No sql statement has been red from the file."); } else _result = new MySqlResult("", "No file has been specified."); return _result; }
/// <summary> /// Loads the script. /// </summary> /// <param name="path">The path.</param> public void LoadScript(string path) { IsLoading = true; CurrentScript = new FileInfo(path); if (CurrentScript.Exists) { this.Text = CurrentScript.Name; scriptBox1.Editor.Document.Text = CurrentScript.Read(); btnSave.Enabled = false; MethodCall.ExecuteSafeThreadIn(new Callback(delegate() { scriptBox1.Editor.Document.ParseAll(); IsLoading = false; }), 500); } else { CurrentScript = null; return; } SetStatusText("Script '", CurrentScript.FullName, "' is opened!"); }
public void NewScript() { var fi = new FileInfo(Path.Combine(Application.StartupPath, "ScriptConfig\\ScriptInfo.txt")); if (fi.Exists) { scriptBox1.Editor.Document.Text = fi.Read(); } else { scriptBox1.Editor.Document.Text = string.Empty; } this.Text = string.Concat("CaveBot - New Script*"); CurrentScript = null; btnSave.Enabled = false; HidePanels(); MethodCall.ExecuteSafeThreadIn(new Callback(delegate() { scriptBox1.Editor.Document.ParseAll(); if (CurrentScript == null) { scriptBox1.Editor.Caret.MoveDown(scriptBox1.Editor.Document.Lines.Length - 1, false); } }), 1000); }