Method to pick a file

Which method we should use then to pick up a file from windows file picker dialog?
Thanks

I don’t know your specific requirements, but File::GetFileFromUser() may be what you’re looking for.

Here is my code:

public static void main(Args _args)
{
Dialog dialog = new Dialog();
DialogField dialogField;
AsciiIo importFile;
str filePath,fileNameOnly;
filetype type;
container record;
str delimiter = “,”;
int totalRecords;
CustGroup custGrp;

dialogField=dialog.addField(extendedTypeStr(FilenameOpen),“Select File”,“Select file to import”);
dialog.caption(“File Picker”);
dialog.filenameLookupFilter([‘csv’,’*.csv’]);

if(!dialog.run())
return;

[filePath, fileNameOnly, type] = fileNameSplit(dialogField.value());
importFile = new AsciiIo(dialogField.value(), ‘R’);

if((!importFile) || (importFile.status() != IO_Status::Ok))
{
warning(“Error in opening import file”);
throw(Exception::Error);
}

importFile.inFieldDelimiter(Delimiter);

try
{
ttsbegin;
custGrp.clear();
record = importFile.read(); // First row - Column name - Header

while(importFile.status() == IO_Status::Ok)
{
record = importFile.read();
if(!record)
break;

totalRecords = totalRecords + 1;
custGrp.clear();

custGrp.CustGroup = conPeek(record, 1);
custGrp.Name = conPeek(record,2);

custGrp.insert();
}
ttscommit;
}

catch(Exception::Error)
{
Throw(Exception::Error);
}

info(strFmt(“Total Read Records = %1”,totalRecords));
}

from above code “dialog.filenameLookupFilter([‘csv’,’*.csv’]);” throws error. above code works in AX 2012 but not working in D365OF

your suggestion is highly appreciated,
Thanks

That’s correct. This piece of code is for older versions of AX; it’s not applicable to Dynamics 365.