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 :
Microsoft Dynamics AX (Archived)

Read a particular value from a List

(0) ShareShare
ReportReport
Posted on by

Hi all,

I need to extract a file name from complete path and I see it strange that I when I split the path, I need to iterate through the list to get the file name. Why can't I just get the value simply by calling myList(3) as in DotNet, instead of having to instantiate an iterator, then loop through the records.

Here is my code;

 List strlist=new List(Types::String); 
 strlist = strSplit(CompletePath, @"\");

After doing this I should have a list of all the different parts. Is there any simple form to read the list, like 
FileName = strlist[2]; instead of having to do the below;
iterator = new ListIterator(strlist);
while(iterator.more())
{
FileName = iterator.value();
if (_Value == "myFile")
{
 _NotFound=boolean::false;
}

Here again, if at that very moment, I don't know the file name, how do I check?

Thanks in anticipation for your support.

*This post is locked for comments

I have the same question (0)
  • Anton Venter Profile Picture
    20,656 Super User 2026 Season 1 on at

    Hi, it's not possible with a List. Using a Map will give you this type of functionality because you can then specify the key as an integer.

  • Suggested answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    You're comparing different structures. You shouldn't expect that if you find classes with the same name in different solutions (AX and .NET in this case), they'll work the same. Linked list generally don't allow access by index, which is true for LinkedList in .NET as well.

    Your particular requirement (if I got what you're trying to do) can be easily achieved by calling System.IO.Path::GetFileName().

    You could also parse the path by yourself, convert the list to a container or Set and so on....

    Also note that you can use just false instead of boolean::false.

  • Community Member Profile Picture
    on at

    You can assign the list to a container with the pack() method and then access the container at a specific postion.

    container con = list.pack();

    conpeek(con, 5);

    Note that the first three places in the container are additional fields and the list starts at position four.

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    (Mis)using pack() for this is a bad idea. It's violates the contract (pack() in intended for another purpose), the solution depends on implementation details that can easily change and developers would likely use it wrong, which would lead to problems with quality.

    If you want a conversion function, just write it - and use the right contract for that (= iterate the list and put elements to a container).

  • Anton Venter Profile Picture
    20,656 Super User 2026 Season 1 on at

    Nadeem, have a look at Docu::splitFileName and Docu::getFileName.

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans