/// <summary> /// Saves the CSV file. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="csvFile">The CSV file.</param> public static void SaveCsvFile(string fileName, CsvFile csvFile) { Contract.Requires(fileName != null); FileSystemUtils.DeleteWithBackup(fileName, false); using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture)) { m_SerializerCurrentCsvFile.Value.Serialize(stringWriter, csvFile, EmptyXmlSerializerNamespaces.Value); File.WriteAllText(fileName, stringWriter.ToString()); } }
private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { appSetting = new AppSetting() { CoursePath = txtCoursePath.Text, DatabasePath = txtDBPath.Text, OutputPath = txtOutputPath.Text, Decrypt = chkDecrypt.Checked, CreateSub = chkCreateSub.Checked, DeleteAfterDecrypt = chkDelete.Checked, ClipIndexAtOne = chkStartClipIndexAt1.Checked, ModuleIndexAtOne = chkStartModuleIndexAt1.Checked }; File.WriteAllText("setting.json", JsonConvert.SerializeObject(appSetting)); }
private void DoNodesForFolder(string cat, string sub) { string currPath = path + cat + "\\" + sub + "\\"; string[] fl = Directory.GetFiles(currPath, "*.*", SearchOption.AllDirectories) .Where(s => s.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase)).ToArray(); foreach (string f in fl) { string nm = f.Substring(path.Length + 2 + cat.Length + sub.Length); nm = nm.Substring(0, nm.Length - 4); string nameForFile = f.Substring(0, f.Length - 4); string txtFile = nameForFile + ".txt"; string fullTextFile = nameForFile + " Full Text.txt"; string[] contents; if (File.Exists(txtFile)) { contents = File.ReadLines(txtFile).ToArray(); } else { File.WriteAllText(txtFile, nm); contents = new string[1]; contents[0] = nm; } string ft = ""; if (File.Exists(fullTextFile)) { string[] ftLines = File.ReadLines(fullTextFile).ToArray(); foreach (string s in ftLines) { ft += s + " "; } ft = ft.Trim(); } List <string> goodTags = new List <string>(); for (int i = 1; i < contents.Length; i++) { if (contents[i] != "") { goodTags.Add(contents[i]); } } files.Add(new DataFile(contents[0], goodTags.ToArray(), cat, sub, nm, ft)); } }
public void TestReadAllTextEncoding() { var filename = new StringBuilder(longPathDirectory).Append(@"\").Append("file3.ext").ToString(); const string fileText = "test"; using (File.CreateText(filename)) { } try { File.WriteAllText(filename, fileText, Encoding.Unicode); Assert.AreEqual(fileText, File.ReadAllText(filename, Encoding.Unicode)); } finally { File.Delete(filename); } }
public DataFile(string n, string[] t, string y, string s, string f, string ft = "") { name = n; tags = t; type = y; subject = s; fileName = f; if (ft == "") { fullText = ""; Stream fileStream = File.OpenRead(GetPDFPath()); PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream); foreach (PdfPageBase page in loadedDocument.Pages) { fullText += page.ExtractText(true).ToLower() + " "; } loadedDocument.Close(); File.WriteAllText(GetFullTextPath(), fullText); } else { fullText = ft; } }
public static void WriteAllText(string path, string contents, Encoding encoding) { File.WriteAllText(path, contents, encoding); }
public static void WriteAllText(string path, string contents) { File.WriteAllText(path, contents); }
public void TestWriteAllTextNullPath() { Assert.Throws <ArgumentNullException>(() => File.WriteAllText(null, "test")); }
public void TestWriteAllTextNullPath() { File.WriteAllText(null, "test"); }