Article | 60000651 |
Type | HowTo |
Product | Engine |
Version | 6 |
Date Added | 9/26/2008 |
Submitted by | Stavros Meimaroglou |
Keywords |
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string GetSaveDlgFilterFormats()
{
string filetypes = "";
filetypes += "VDML (*.vdml)|*.vdml|";
filetypes += "vdcl (*.vdcl)|*.vdcl|";
filetypes += "DXF 2004 (*.dxf)|*.dxf|";
filetypes += "DXF 2000 (*.dxf)|*.dxf|";
filetypes += "DXF 12 (*.dxf)|*.dxf|";
filetypes += "|";
return filetypes;
}
public string GetSaveFileNameDlg(ref string version)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = GetSaveDlgFilterFormats();
if (version == "") version = vdFramedControl1.BaseControl.ActiveDocument.Version.ToUpper();
string defaultFileName = vdFramedControl1.BaseControl.ActiveDocument.FileName;
if (defaultFileName == "") defaultFileName = "VectorDraw"; // use your default name here
if (defaultFileName != null && defaultFileName != "")
{
saveFileDialog1.FileName = VectorDraw.Professional.Utilities.vdGlobals.GetFileNameWithoutExtension(defaultFileName);
saveFileDialog1.InitialDirectory = VectorDraw.Professional.Utilities.vdGlobals.GetDirectoryName(defaultFileName);
int FilterIndex = 1;
if (defaultFileName.EndsWith(".dxf", StringComparison.InvariantCultureIgnoreCase))
{
switch (version)
{
case "DXF2004":
FilterIndex = 3;
break;
case "DXF2000":
FilterIndex = 4;
break;
case "DXF12":
FilterIndex = 5;
break;
default:
break;
}
}
saveFileDialog1.FilterIndex = FilterIndex;
}
saveFileDialog1.RestoreDirectory = true;
DialogResult res = saveFileDialog1.ShowDialog(this);
Application.DoEvents();
if (res != DialogResult.OK) return null;
switch (saveFileDialog1.FilterIndex)
{
case 3:
version = "DXF2004";
break;
case 4:
version = "DXF2000";
break;
case 5:
version = "DXF12";
break;
default:
break;
}
return saveFileDialog1.FileName;
}
private void saveas_Click(object sender, EventArgs e)
{//VDF,VDI,VDCL,VDML does not have versions.
string version = "DXF12";//propose this version or "DXF2000" or "DXF2004". Change to an empty string so the version of existing document will be selected.
vdFramedControl1.BaseControl.ActiveDocument.Filename= @"c:\temp\mydrawing.dxf"; // use the proposed path and the proposed name here
string fname = GetSaveFileNameDlg(ref version); // the filename (including path) that user chose
if (fname == null) return; // user canceled save.
vdFramedControl1.BaseControl.ActiveDocument.SaveAs(fname, null, version);
}
}