Hi Mahesh,
Recenlty, I did the same thing in one of the project I was working on. Below is the code to traverse through the directory and return the files in container variable:
private container getListOfImportFiles()
{
System.Array files;
InteropPermission permission;
counter fileCounter;
container fileList;
;
permission = new InteropPermission(InteropKind::ClrInterop);
permission.assert();
files = CLRInterop::staticInvoke("System.IO.Directory", "GetFiles", YourDirectoryPath, "*.csv");
for (fileCounter = 0; fileCounter < ClrInterop::getAnyTypeForObject(files.get_Length()); fileCounter++)
{
fileList = conins(fileList, conLen(fileList)+1, ClrInterop::getAnyTypeForObject(files.GetValue(fileCounter)));
}
CodeAccessPermission::revertAssert();
return fileList;
}
After this, you can write the code to read the files one by one. Code is shown below:
FileName importFileName;
Counter counter;
container fileList;
FileIOPermission permission;
CommaTextIo file;
container line;
int recordCount;
if (conlen(fileList) > 0)
{
for (counter =1; counter <= conlen(fileList); counter++)
{
importFileName = conPeek(fileList, counter);
permission = new FileIOPermission(importFileName, "RW" );
permission.assert();
file = new CommaTextIo(importFileName, #io_read);
if (!file || file.status() != IO_Status::Ok)
{
throw error("File not found");
}
file.inFieldDelimiter(',');
line = file.read();
while (file.status() == IO_Status::Ok)
{
recordCount++;
// process the file here by using the container variable 'line'
line = file.read();
}
file = null;
CodeAccessPermission::revertAssert();
} // End for loop
} // End outer If clause
For document attachment, refer to the below code:
private void attachDoc(RefTableId _refTableId, RefRecId _refRecId, selectableDataArea _refCompanyId, FileName _name)
{
DocuRef docuRef;
DocuActionArchive archive;
FileName fileName;
;
// Get the file name only.
fileName = conPeek(fileNameSplit(_name), 2);
docuRef.clear();
docuRef.RefRecId = _refRecId;
docuRef.RefTableId = _refTableId;
docuRef.RefCompanyId = _refCompanyId;
docuRef.Name = fileName;
docuRef.TypeId = YourTypeID;
docuRef.insert();
archive = new DocuActionArchive();
archive.insertDocuValue(docuRef, _name);
//archive.add(docuRef, _name);
}
Please verify and let me know if you have further queries.
Thanks,
Baber.