public DeleteDocument ( string path ) : void | ||
path | string | |
Résultat | void |
private void btnSave_Click_1(object sender, RibbonControlEventArgs e) { IDocumentProcessorService documentProcessorService = new DocumentProcessorService(); _Application wordApp; try { wordApp = (_Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application"); } catch (Exception) { wordApp = new Microsoft.Office.Interop.Word.Application(); } string newFileName; var aDoc = wordApp.ActiveDocument; string fileName = aDoc.Name; int dotPosition = fileName.IndexOf(".", 1, System.StringComparison.Ordinal); switch (dotPosition) { case -1: { // Ask where it should be saved var dlg = new SaveFileDialog() { RestoreDirectory = true, OverwritePrompt = true, Title = "Enter the file name of the template", }; dlg.ShowDialog(); fileName = dlg.FileName; } break; default: fileName = fileName.Substring(0, aDoc.Name.Length - (aDoc.Name.Length - dotPosition)); fileName = Properties.Settings.Default.DefaultPath.ToString() + fileName; break; } if (fileName.Trim() == string.Empty) { return; } aDoc.SaveAs(fileName, WdSaveFormat.wdFormatTemplate); aDoc.Close(); documentProcessorService.UploadDocument(1, fileName + ".dot"); documentProcessorService.DeleteDocument(fileName + ".dot"); InsertToLetterTemplate(fileName, GetTemplateType(fileName)); MessageBox.Show("Template is Uploaded.", "Saving", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void btnSave_Click_1(object sender, RibbonControlEventArgs e) { IDocumentProcessorService documentProcessorService = new DocumentProcessorService(); _Application wordApp; try { wordApp = (_Application) System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application"); } catch (Exception) { wordApp = new Microsoft.Office.Interop.Word.Application(); } string newFileName; var aDoc = wordApp.ActiveDocument; string fileName = aDoc.Name; int dotPosition = fileName.IndexOf(".", 1, System.StringComparison.Ordinal); switch (dotPosition) { case -1: { // Ask where it should be saved var dlg = new SaveFileDialog() { RestoreDirectory = true, OverwritePrompt = true, Title = "Enter the file name of the template", }; dlg.ShowDialog(); fileName = dlg.FileName; } break; default: fileName = fileName.Substring(0, aDoc.Name.Length - (aDoc.Name.Length - dotPosition)); fileName = Properties.Settings.Default.DefaultPath.ToString() + fileName; break; } if (fileName.Trim() == string.Empty) return; aDoc.SaveAs(fileName,WdSaveFormat.wdFormatTemplate); aDoc.Close(); documentProcessorService.UploadDocument(1,fileName + ".dot"); documentProcessorService.DeleteDocument(fileName + ".dot"); InsertToLetterTemplate(fileName, GetTemplateType(fileName)); MessageBox.Show("Template is Uploaded.", "Saving", MessageBoxButtons.OK, MessageBoxIcon.Information); }