Class
SSLCSVRead
{
public
static void main (Args _args)
{
AsciiStreamIo
filestreamio;
Array
csvreadlines;
FileUploadTemporaryStorageResult
filegetUpload;
container
recordget;
filegetupload
= Filed::GetFileFromUser() as FileUploadTemporaryStorageResult;
fileStreamio
= AscciStreamIO::ConstructforRead(filegetupload.openResult());
if(filestreamio)
{
if(filestreamIo.status())
{
throw
error("file error- check file and location");
}
filestreamio.inFieldDelimiter(',');
filestreamio.inRecordDelimiter('\r\n');
}
while(!filestreamio.status())
{
recordget
= filestreamion.read();
if(conlen(recordget))
{
info(strfmt("%1-%2",conpeek(recordget,1),conpek(recordget,2)));
}
}
info("CSV
file read - completed");
}
}
Sample 2:
System.IO.Stream stream;
DialogGroup dlgUploadGroup;
FileUploadBuild fileUploadBuild;
FormBuildControl formBuildControl;
Dialog dialog = new Dialog(#ImportOrderFile);
container record;
CommaTextStreamIo fileImport;
dlgUploadGroup = dialog.addGroup('@SYS54759');
formBuildControl = dialog.formBuildDesign().control(dlgUploadGroup.name());
fileUploadBuild = formBuildControl.addControlEx(classstr(FileUpload), formControlStr(SalesTable, <Control Name>));
infolog.clear();
fileUploadBuild.style(FileUploadStyle::MinimalWithFilename);
fileUploadBuild.fileTypesAccepted(#FileType);
if (dialog.run() && dialog.closedOk())
{
FileUpload fileUploadControl = dialog.formRun().control(dialog.formRun().controlId(formControlStr(SalesTable, <Control Name>)));
FileUploadTemporaryStorageResult result = fileUploadControl.getFileUploadResult() as FileUploadTemporaryStorageResult;;
str textFile;
if (result != null && result.getUploadStatus())
{
textFile = result.getDownloadUrl();
}
fileImport = CommaTextStreamIo::constructForRead(File::UseFileFromURL(textFile));
if (fileImport)
{
if (fileImport.status())
{
throw error("@SYS52680");
}
fileImport.inFieldDelimiter(',');
fileImport.inRecordDelimiter('\r\n');
}
while (!fileImport.status())
{
record = fileImport.read();
if (conLen(record))
{
if (header)
{
header = false;
continue;
}
//staging table insert method
}
}
table.insertDatabase();
}
Sample 2:
System.IO.Stream stream;
DialogGroup dlgUploadGroup;
FileUploadBuild fileUploadBuild;
FormBuildControl formBuildControl;
Dialog dialog = new Dialog(#ImportOrderFile);
container record;
CommaTextStreamIo fileImport;
dlgUploadGroup = dialog.addGroup('@SYS54759');
formBuildControl = dialog.formBuildDesign().control(dlgUploadGroup.name());
fileUploadBuild = formBuildControl.addControlEx(classstr(FileUpload), formControlStr(SalesTable, <Control Name>));
infolog.clear();
fileUploadBuild.style(FileUploadStyle::MinimalWithFilename);
fileUploadBuild.fileTypesAccepted(#FileType);
if (dialog.run() && dialog.closedOk())
{
FileUpload fileUploadControl = dialog.formRun().control(dialog.formRun().controlId(formControlStr(SalesTable, <Control Name>)));
FileUploadTemporaryStorageResult result = fileUploadControl.getFileUploadResult() as FileUploadTemporaryStorageResult;;
str textFile;
if (result != null && result.getUploadStatus())
{
textFile = result.getDownloadUrl();
}
fileImport = CommaTextStreamIo::constructForRead(File::UseFileFromURL(textFile));
if (fileImport)
{
if (fileImport.status())
{
throw error("@SYS52680");
}
fileImport.inFieldDelimiter(',');
fileImport.inRecordDelimiter('\r\n');
}
while (!fileImport.status())
{
record = fileImport.read();
if (conLen(record))
{
if (header)
{
header = false;
continue;
}
//staging table insert method
}
}
table.insertDatabase();
}
No comments:
Post a Comment