public void ShowPreviewTemplateButton_Click(object sender, EventArgs e) { string name, fileName; byte[] body; DownLoadFromBase(out name, out fileName, out body); var ind = Server.MapPath("~").LastIndexOf("\\"); var path = string.Format(@"{0}\update\{1}{2}", Server.MapPath("~").Substring(0, ind), name, Path.GetExtension(fileName)); try { File.WriteAllBytes(path, body); using (WordInterop wi = new WordInterop()) wi.SaveWithHtmlExtension(path); } catch (Exception ex) { throw new Exception("Ошибка при создании файла:\r\n" + ex.Message); } try { // FileStream read = File.OpenRead(Path.ChangeExtension(path, "htm")); File.Delete(path); } catch { } }
private string SavePreviewTemplate() { string extension = string.Empty; byte[] body = null; DownLoadTemplateFromBase(out extension, out body); //вложить в cache папку if (body == null || string.IsNullOrEmpty(extension)) { return(string.Empty); } var pathForFormat = DirectoryPath + string.Format(@"\{0}{1}", TemplateID.ToString(), extension); try { File.WriteAllBytes(pathForFormat, body); } catch { throw new Exception(string.Format("Файл с расширением {0} не загрузился", extension)); } try { if (TemplateType == "wordbased") { using (var wi = new WordInterop()) wi.SaveWithHtmlExtension(pathForFormat); } else if (TemplateType == "excelbased") { using (var ei = new ExcelInterop()) ei.SaveWithHtmlExtension(pathForFormat); } } catch { #if EXCLUDED throw new Exception("Не сохранился файл с расширением html"); #endif return(string.Empty); } try { File.Delete(pathForFormat); } catch { throw new Exception(string.Format("Файл с расширением {0} не удалился", extension)); } return(TemplateID.ToString() + ".html"); }
private async void BtnWord_Click(object sender, RoutedEventArgs e) { PnlControls.IsEnabled = false; try { await Task.Run(() => { var w = new WordInterop(); w.Convert(page.Data, page.Imgs, page.Lang); }); } catch (Exception ex) { MessageBox.Show($"{ex.Message}\n-----------------\n{ex.StackTrace}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { PnlControls.IsEnabled = true; } }