web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

CSV Export from Enterprise Portal

(0) ShareShare
ReportReport
Posted on by 165

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();
}

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,884 Most Valuable Professional on at

    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.

  • mrpequit Profile Picture
    165 on at

    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.

  • Martin Dráb Profile Picture
    237,884 Most Valuable Professional on at

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans