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, ...
Answered

How to access Path of a file using x++

(0) ShareShare
ReportReport
Posted on by 61

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

I have the same question (0)
  • Suggested answer
    Komi Siabi Profile Picture
    13,107 Most Valuable Professional on at

    You can use the StrFmt:

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

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

    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?

  • Dinesh Tyagi Profile Picture
    61 on at

    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

  • Dinesh Tyagi Profile Picture
    61 on at

    Hi Komi,

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

    Thanks & Regards

    Dinesh

  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    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
    61 on at

    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

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 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans