Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to access Path of a file using x++

(0) ShareShare
ReportReport
Posted on by 37

Hi,

I want to access a file which is located on Desktop using x++ for Reading.

I have a text file as an input, let say, 'input.txt', I need to concatenate filepath with input.txt. I have used filepath = @"C:\Users\Dinesh\desktop\",

& did this filepath + fileName = @"C:\Users\desktop\input.txt" but this is not working.

Also I have used System.IO.Path::getFullPath('input.txt'), but this returned the wrong path.

Is their any other way to get the file path using x++ ?

Thanks & Regards,

Dinesh

  • Dinesh Tyagi Profile Picture
    37 on at
    RE: How to access Path of a file using x++

    Hi Martin,

    Thanks for the quick reply.

    As you Suggest I have created a file upload option & now I am able to Upload file & can process data in it.

    Thanks & Regards,

    Dinesh

  • Verified answer
    Martin Dráb Profile Picture
    232,093 Most Valuable Professional on at
    RE: How to access Path of a file using x++

    Moved from Dynamics AX forum.

    X++ runs on a web server in an Azure data center; it can't connect to users machines machines and manipulate their files. Therefore the your design is fundamentally wrong.

    What you can do is giving users an option to upload a file that you'll then process in your class.

  • Dinesh Tyagi Profile Picture
    37 on at
    RE: How to access Path of a file using x++

    Hi Komi,

    I have used as you suggest but the file is not opening using this fullpath which got through strfmt.

    Thanks & Regards

    Dinesh

  • Dinesh Tyagi Profile Picture
    37 on at
    RE: How to access Path of a file using x++

    Hi Martin,

    Thanks for the Suggestion. 

    I am using the current version of D365 finance & operations.

    Actually, I am working on SysOperationFramework, I want to access a file located on my desktop & will do something with the data of the file. 

    I am passing FileName as parameter in Contract class & then in Service class I will concatenate filePath & fileName to get the full path of the file & can access it.

    On my system Desktop path is : @"C:\Users\Dinesh\desktop\" I have used it but was not able to access that file.

    I am using StreamReader class to open the file for reading : System.IO.StreamReader streamReader = new System.IO.StreamReader(sTempPath + sFileName);

    Before that I have used this : System.IO.Path::GetTempPath(); to access the Temp folder on windows & with this I have read the file located in windows temp folder & access the data, it was working fine but when I did this same task in Batch using SysFramework that time I got the wrong path of temp folder.

    So, I want to access the file path that must work same in Synchronous & in batch process as well.

    Thanks & Regards,

    Dinesh

  • Martin Dráb Profile Picture
    232,093 Most Valuable Professional on at
    RE: How to access Path of a file using x++

    Please never describe a problem by mere "it's not working", because there is no universal solution for all possible problems. Describe your particular issue.

    Also, what version of AX is it about?

  • Suggested answer
    Komi Siabi Profile Picture
    12,789 Most Valuable Professional on at
    RE: How to access Path of a file using x++

    You can use the StrFmt:

    str FileToAccess = strFmt("%1%2",filepath,fileName)

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,296 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,093 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans