Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 643247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:15:43+00:00 2026-05-13T21:15:43+00:00

I’ve got two arrays where I want to find all the elements in Array0

  • 0

I’ve got two arrays where I want to find all the elements in Array0 where the full string from Array1 is contained in the string of Array0. Here is the scenario:

I’ve got a string array that contains the full path of all the xml files in a certain directory. I then get a list of locations and only want to return the subset of xml file paths where the filename of the xml file is the loc id.

So, my Array0 has something like:

c:\some\directory\6011044.xml
c:\some\directory\6028393.xml
c:\some\directory\6039938.xml
c:\some\directory\6028833.xml

And my Array1 has:

6011044
6028833

…and I only want to have the results from Array0 where the filepath string contains string from Array1.

Here is what I’ve got…

 filesToLoad = (from f in Directory.GetFiles(Server.MapPath("App_Data"), "*.xml")
   where f.Contains(from l in locs select l.CdsCode.ToString()) 
   select f).ToArray();

…but I get the following compiler error…

Argument '1': cannot convert from 'System.Collections.Generic.IEnumerable<string>' to 'string'

…which I can understand from an English standpoint, but do not know how to resolve.

Am I coming at the from the wrong angle?

Am I missing just one piece?

EDIT

Here is what I’ve changed it to:

filesToLoad = (Directory.GetFiles(Server.MapPath("App_Data"), "*.xml"))
     .Where(path => locs.Any(l => path.Contains(l.CdsCode.ToString()))
 ).ToArray();

…but this still gets me all the .xml files even though one of them is not in my locs entity collection. What did I put in the wrong place?

Obviously I’m missing the main concept so perhaps a little explanation as to what each piece is doing would be helpful too?

Edit 2
See Mark’s comment below. The answer to my problem, was me. I had one record in my locs collection that had a zero for the CDS value and thus was matching all records in my xml collection. If only I could find a way to code without myself, then I’d be the perfect developer!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:15:43+00:00Added an answer on May 13, 2026 at 9:15 pm

    You’re missing Any:

    string[] result = paths.Where(x => tests.Any(y => x.Contains(y))).ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.