Linq statement - variable is not empty

I have this Linq statement: Folder.FirstOrDefault(function(item) item.Name=" ")

I want to amend it as I would like it to say if the name is not empty/ if it exists

How would I do that?

Hi @E.T.S ,

Could you provide us with bit more context on what are you trying to perform and What is the datatype of Folder variable ?

Hi @E.T.S

Try this:

Folder.FirstOrDefault(Function(item) Not String.IsNullOrWhiteSpace(item.Name))

String.IsNullOrWhiteSpace(item.Name) checks if the item.Name is not null and not empty or contains only white spaces. So, Not String.IsNullOrWhiteSpace(item.Name) checks if the name is not empty (it exists and has content).

Hope it helps!!

I am trying to download files from a sharepoint site - the output of the find files and folders activity is a drive item array so I thought I could use a linq statement in order to get the correct variable type for the download activity

This works! But it won’t work in a for each loop

Hi @E.T.S

Use this:

diInputsFolderLoop = Folder.Where(Function(item) Not String.IsNullOrWhiteSpace(item.Name)).ToList()

// Use a For Each loop to iterate through the filtered results
For Each item In filteredFolders
    // Perform actions for folders with non-empty names here
Next

Hope it helps!!

@E.T.S ,

A Filtering that could be recognised when using the Find Files and Folders is that, you would only want to Download files from that Specified folder provided. But the activity also returns us the Folders as well, which would give out an Error when used in Download File activity.

So, We use the below Expression to only preserve the type File from the Drive Item array :

DriveItemArrayVar = DriveItemArrayVar.Where(Function(x)x.File IsNot Nothing).ToArray

You could then use the DriveItemArrayVar in the ForEach activity.

Not sure, if this was the concern, as you mentioned below :

Cross reference:

As mentioned we do have some version / packages miss-harmonies

Maybe too quick dirty for sanitizing the loop issue

  • an index driven access by a loop over Enumerable.Range / Repeat number of times in combination with the output.count could be exploited as a workaround