1-) C# RMOS - TreeList print ve dışa aktarma excel pdf vs. SaveFileDialog
private void btnExeleAktar_Click(object sender, EventArgs e)
{
yazdir(treeList1);
}
public void yazdir(TreeList treeList)
{
using (SaveFileDialog saveDialog = new SaveFileDialog())
{
saveDialog.Filter = "Excel (2003)(.xls)|*.xls|Excel (2010) (.xlsx)|*.xlsx |RichText File (.rtf)|*.rtf |Pdf File (.pdf)|*.pdf |Html File (.html)|*.html";
if (saveDialog.ShowDialog() != DialogResult.Cancel)
{
string exportFilePath = saveDialog.FileName;
string fileExtenstion = new FileInfo(exportFilePath).Extension;
switch (fileExtenstion)
{
case ".xls":
treeList.ExportToXls(exportFilePath);
break;
case ".xlsx":
treeList.ExportToXlsx(exportFilePath);
break;
case ".rtf":
treeList.ExportToRtf(exportFilePath);
break;
case ".pdf":
treeList.ExportToPdf(exportFilePath);
break;
case ".html":
treeList.ExportToHtml(exportFilePath);
break;
default:
break;
}
if (File.Exists(exportFilePath))
{
try
{
//Try to open the file and let windows decide how to open it.
var p = new Process();
p.StartInfo = new ProcessStartInfo(exportFilePath)
{
UseShellExecute = true
};
p.Start();
}
catch
{
String msg = "The file could not be opened." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
String msg = "The file could not be saved." + Environment.NewLine + Environment.NewLine + "Path: " + exportFilePath;
MessageBox.Show(msg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}