private void btnConvertToPdf_Click(object sender, EventArgs e) { string dbt_wfile = ""; OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) { dbt_wfile = dlg.FileName; string pdf_file = Path.ChangeExtension(dbt_wfile, ".pdf"); string ext = Path.GetExtension(dbt_wfile).Replace(".", ""); switch (ext.ToLower()) { case "docx": case "doc": if (!File.Exists(pdf_file)) { NCWord.ConvertWordPDF(dbt_wfile, pdf_file); } break; case "xlsx": case "xls": if (!File.Exists(pdf_file)) { NCExcel excel = new NCExcel(); excel.OpenExcelFile(dbt_wfile); excel.SaveAsPDF(pdf_file); excel.Close(); } break; case "pptx": case "ppt": if (!File.Exists(pdf_file)) { NCPPT ppt = new NCPPT(); if (ppt.PPTOpen(dbt_wfile)) { ppt.PPTSaveAsPDF(pdf_file); ppt.PPTClose(); } } break; } } }