Prod.: Engine, ver.: 6, ID: 60001758, HowTo : How to Filter in OpenFileDialog and SaveFileDialog

HowTo : How to Filter in OpenFileDialog and SaveFileDialog

Article60001758
TypeHowTo
ProductEngine
Version6
Date Added7/17/2012
Submitted byAl? Niazi
Keywords

Subject

How to Filter in OpenFileDialog and SaveFileDialog

Summary

I need to allow only some specific file types to be opened and saved from my app. For example vdml/vdcl and png files. How can I do this ?

Solution

You need to use the OnGetSaveFileFilterFormat and OnGetOpenFileFilterFormat events and add a code like:
void ActiveDocument_OnGetSaveFileFilterFormat(ref string saveFilter)
{
   string versions = "";
   saveFilter = "";
   saveFilter += "VDML (*.vdml)|*.vdml|"; versions += "?VDML";
   saveFilter += "vdcl (*.vdcl)|*.vdcl|"; versions += "?VDCL";
   saveFilter += "PNG (*.png)|*.png|"; versions += "?PNG";
   saveFilter += "|";
  saveFilter += versions;
}

void ActiveDocument_OnGetOpenFileFilterFormat(ref string openFilter)
{
   openFilter = "All Drawing Files (*.vdml;*.vdcl;*.png;)|*.vdml;*.vdcl;*.png;";
   openFilter += "|VDML Document (*.vdml)|*.vdml"; //add VDML
   openFilter += "|vdcl Document (*.vdcl)|*.vdcl"; //add VDCL
   openFilter += "|PNG Files (*.PNG)|*.PNG"; // add PNG
   openFilter += "|All Files(*.*)|*.*||";
}