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 :
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,345 Super User 2025 Season 2 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
    237,898 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
    237,898 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,345 Super User 2025 Season 2 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

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

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans