Every once in a while, it could be useful for the end-user to have the option of importing several files through the UI.
I have found two similar examples on how to achieve this:
Example 1)
static void MultiFileSelectDlgTest_1(Args _args)
{
System.Windows.Forms.OpenFileDialog ofd;
System.String[] s2;
int counters;
str imageValaue;
int i;
;
ofd = new System.Windows.Forms.OpenFileDialog();
ofd.set_Title("Select files");
ofd.set_Multiselect(true);
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult::OK)
{
s2 = ofd.get_FileNames();
counters=System.Convert::ToInt32( s2.get_Length());
for(i = 0 ; i <= counters-1; i++)
{
imageValaue = System.Convert::ToString(s2.GetValue(i));
info(strFmt('%1', imageValaue));
//do whatever you want ;)
}
}
}
The dialog will show this:
and the output in the infolog shows the individual files processed:
Example 2) The second example is just another flavour of the first, adding a filter option on the input content.
static void MultiFileSelectDlgTest_2(Args _args)
{
int idx;
int cnt;
boolean result;
System.String[] files;
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.set_Multiselect(true);
dlg.set_DefaultExt(".txt");
dlg.set_Filter("Text documents|*.txt|All files|*.*");
result = dlg.ShowDialog();
if (result)
{
files = dlg.get_FileNames();
cnt = files.get_Count();
for (idx = 0; idx <= cnt; idx++)
{
info(files.get_Item(idx));
}
}
}
No comments:
Post a Comment