Get File stream and changes the content and upload file stream again
//Convert downloaded url to string
System.IO.Stream memoryStream = File::UseFileFromURL(DMFStagingWriter::getDownloadURLFromFileId(_uploadedStatement));
memoryStream.Position = 0;
System.IO.StreamReader sReader = new System.IO.StreamReader(memoryStream);
// Set file contentn string
str fileContent = sReader.ReadToEnd();
container conOld = str2con(fileContent,"\r\n");
str newFileContent,contentStr;
int i;
boolean hasCustom;
for (i = 1; i<= conLen(conOld); i++)
{
contentStr = conPeek(conOld,i) ;
int strlen = strLen(contentStr);
int commaCount = strLen(strKeep(contentStr,","));
if(commaCount <10)
{
str lastStr = subStr(contentStr,strlen,1);
if(lastStr == "/")
{
newFileContent += subStr(contentStr,0,strlen-1)+strRep(",",10-commaCount)+"/"+"\r\n";
}
else
{
newFileContent += contentStr+ strRep(",",10-commaCount)+"\r\n";
}
hasCustom = true;
}
else
{
newFileContent += contentStr+"\r\n";
}
}
if(hasCustom)
{
current.parmInputDataStream(ANTHBankStatementImportBatch::generateStreamFromString(newFileContent));
}
//Convert string to File stream
public static System.IO.Stream generateStreamFromString(str _text)
{
System.Byte[] byteArray;
System.IO.MemoryStream memoryStream;
byteArray = System.Text.Encoding::UTF8.GetBytes(_text);
memoryStream = new System.IO.MemoryStream(byteArray);
return memoryStream;
}
Comments
Post a Comment