Announcements
Hello all,
I've created a new class that exports CSV from selected records on the list page.
It's working fine when run on AX client, but when running the button from Enterprise Portal, it doesn't save the CSV file on the folder. No errors encountered.
Is there additional permissions needed? Below is my code:
client server public static void main(Args _args)
{
#File
#xppTexts
CommaIo file;
container line;
str filepath;
container confilter = ['.csv', '*.csv'];
CommaTextIo commaTextIo;
FileIOPermission permission;
tableA tableA;
Common multiSelectionRecord;
MultiSelectionContext multiSelectionContext;
TextBuffer textBuffer;
str fileName;
utcDateTime dateTime = DateTimeUtil::getSystemDateTime();
;
fileName = curUserId() + DateTimeUtil::toFormattedStr(dateTime, 231, DateDay::Digits2,
DateSeparator::None, DateMonth::Short, DateSeparator::None, DateYear::Digits4, TimeSeparator::Dot, TimeSeparator::Dot);
filepath = strFmt("C:\\temp\\%1.csv", filename);
new FileIOPermission(filepath, "rw").assert();
textBuffer = new TextBuffer();
//write header
textBuffer.appendText("Item Id");
multiSelectionContext = _args.multiSelectionContext();
if(multiSelectionContext)
{
multiSelectionRecord = multiSelectionContext.getFirst();
tableA = multiSelectionRecord;
while(tableA)
{
textBuffer.appendText(strFmt('%1', tableA.ItemId));
textBuffer.appendText(#newline);
tableA = multiSelectionContext.getNext();
}
}
textBuffer.toFile(filepath, FileEncoding::UTF8);
CodeAccessPermission::revertAssert();
}
Please never describe your problem with mere "it doesn't work". Give us more information.
For example, if you get an error, tell us what the error messages says and where the error was thrown from.
That is works on client proves absolutely nothing. That's executed by a different process (AX client vs. web server), by a different account and often on a different machine. I don't dispute that you have access to C:\Temp on your machine, but that's not the question. We're talking about if Enterprise Portal have access to that path. There may even be no C:\Temp folder on the server where EP is installed.
Hi Martin,
WinAPIIServer/WinAPI doesn't work when called from EP unfortunately. I've also tested the path and I have access to them since the file writes when run on ax client. It now works only for network shared folders.
Please always use Insert > Code (in the rich formatting view) to paste source code. Your code is very difficult to read because you didn't paste it in the right way and line indentation got lost. I tried to fix it for you, but the code looks invalid, because of the extra } at line 41. Can you please review your code and update it?
client server public static void main(Args _args) { #File #xppTexts CommaIo file; container line; str filepath; container confilter = ['.csv', '*.csv']; CommaTextIo commaTextIo; FileIOPermission permission; tableA tableA; Common multiSelectionRecord; MultiSelectionContext multiSelectionContext; TextBuffer textBuffer; str fileName; utcDateTime dateTime = DateTimeUtil::getSystemDateTime(); ; fileName = curUserId() DateTimeUtil::toFormattedStr(dateTime, 231, DateDay::Digits2, DateSeparator::None, DateMonth::Short, DateSeparator::None, DateYear::Digits4, TimeSeparator::Dot, TimeSeparator::Dot); filepath = strFmt("C:\\temp\\%1.csv", filename); new FileIOPermission(filepath, "rw").assert(); textBuffer = new TextBuffer(); //write header textBuffer.appendText("Item Id"); multiSelectionContext = _args.multiSelectionContext(); if(multiSelectionContext) { multiSelectionRecord = multiSelectionContext.getFirst(); tableA = multiSelectionRecord; while(tableA) { textBuffer.appendText(strFmt('%1', tableA.ItemId)); textBuffer.appendText(#newline); tableA = multiSelectionContext.getNext(); } } textBuffer.toFile(filepath, FileEncoding::UTF8); CodeAccessPermission::revertAssert(); }
Anyway, I see that your code assumes that the account that the IIS application pools is running under have permissions to wrote to C:\temp. It normally shoudn't, which is likely the reason of failure. Use WinAPIServer::getTempPath() to get the corrent temporary folder path.
By the way, you could have tested whether you can access the path or not.
André Arnaud de Cal...
293,296
Super User 2025 Season 1
Martin Dráb
232,093
Most Valuable Professional
nmaenpaa
101,156
Moderator