Using MS Common Dialog


Everyone is familar is the Common Dialog - File Open/Save control in Windows, you use it everyday. This script shows you how to script the Common Dialog control and put it to work for you.





// Create the Object

cd = new ActiveXObject("MSComDlg.CommonDialog");



// Set file filter

cd.Filter = "All Files(*.*)|*.*|JScript Files(*.js)|*.js";

cd.FilterIndex = 2;



// Must set MaxFileSize. Otherwise you will get an error

cd.MaxFileSize = 128;



// Show it to user

cd.ShowOpen();



// Retrieve file + path

file = cd.FileName;



// If the user does enter file exit

if ( !file ) {

   WScript.Echo("You must enter a file name");

   WScript.Quit(0);

} else {

   WScript.Echo("The user selected:\n" + file );

}