public static void ExportToExcelFile( DataSet dataSet, string filePath) { if (!filePath.EndsWith(@".xlsx", StringComparison.InvariantCultureIgnoreCase)) { throw new Exception("Currently only XLSX (i.e. not XLS) is supported when writing Excel files."); } var wb = new Workbook(); wb.Worksheets.Clear(); foreach (DataTable table in dataSet.Tables) { var ws = new Worksheet(table.TableName); wb.Worksheets.Add(ws); processSheet(table, ws); } SafeFileOperations.SafeDeleteFile(filePath); wb.Save(filePath); }
private void backupFiles() { lock (_backupLock) { foreach (var resxFile in _resxFiles) { var bak = resxFile.FilePath; // Delete old bak files if (ZlpIOHelper.FileExists(bak.FullName + @".bak")) { // Remove ReadOnly-attribute. removeReadOnlyAttributes( new ZlpFileInfo(bak.FullName + @".bak")); SafeFileOperations.SafeDeleteFile(bak + @".bak"); } SafeFileOperations.SafeCopyFile( resxFile.FilePath.FullName, bak.FullName + @".bak", true); } } }
private void doDispose() { SafeFileOperations.SafeDeleteFile(_tempFilePath); }
/// <summary> /// Store files to FileSystem /// </summary> private void storeFiles() { foreach (var resxFile in _resxFiles) { if (resxFile.FilePath.Exists) { if ((ZlpIOHelper.GetFileAttributes(resxFile.FilePath.FullName) & ZetaLongPaths.Native.FileAttributes.Readonly) != 0) { if (_gridEditableData != null && _gridEditableData.Project != null) { switch (_gridEditableData.Project.ReadOnlyFileOverwriteBehaviour) { case ReadOnlyFileOverwriteBehaviour.Overwrite: // Simply continue to code below. break; case ReadOnlyFileOverwriteBehaviour.Ask: var h = CanOverwrite; resxFile.FilePath.Refresh(); switch (h(resxFile.FilePath)) { case AskOverwriteResult.Overwrite: // Simply continue to code below. break; case AskOverwriteResult.Skip: continue; case AskOverwriteResult.Fail: throw new Exception( string.Format( Resources.SR_DataProcessing_storeFiles_Save_operation_was_cancelled_at_file, resxFile.FilePath.Name)); default: throw new ArgumentOutOfRangeException(); } break; case ReadOnlyFileOverwriteBehaviour.Skip: continue; case ReadOnlyFileOverwriteBehaviour.Fail: throw new Exception( string.Format( Resources.SR_DataProcessing_storeFiles_Saving_failed_because_of_read_only_file, resxFile.FilePath.Name)); default: throw new ArgumentOutOfRangeException(); } } } removeReadOnlyAttributes(resxFile.FilePath); SafeFileOperations.SafeDeleteFile(resxFile.FilePath.FullName); } var settings = new XmlWriterSettings { Indent = true, IndentChars = '\t'.ToString(), Encoding = Encoding.UTF8 }; using (var sw = new StreamWriter( resxFile.FilePath.FullName, false, new UTF8Encoding(false))) using (var write = XmlWriter.Create(sw, settings)) { var doc = resxFile.Document; doc.Save(write); } } }