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

Announcements

No record found.

News and Announcements icon
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 65

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,218 Most Valuable Professional on at

    You can use the StrFmt:

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

  • Martin Dráb Profile Picture
    239,452 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
    65 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
    65 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
    239,452 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
    65 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 622

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 553 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans