Quote Originally Posted by jmcilhinney View Post
Yes, LINQ is .NET 3.5 and later. Unless you have a requirement for .NET 2.0, I'd suggest upgrading.

If you do then your query will be a little different to that. First, there's not much point calling ToString on an element from a String array. Chances are that it is already a String. Also, the array contains full file paths, while it's the file name that starts with that substring. You can use IO.Path.GetFileName to get just the file name.
vb.net Code:
  1. Dim wordDocs = IO.Directory.GetFiles("folder path here", "*.doc").Where(Function(s) Not IO.Path.GetFileName(s).StartsWith("~$")).ToArray()
You can drop the ToArray if you only intend to loop through the list. Also, that uses function syntax but query syntax would obviously be just as valid. It just doesn't feel as natural in this particular scenario to me.

If you want to stick with .NET 2.0 then you'll use a loop. Create a new List from the array and then use a For loop to go backwards through the file paths. When you find a temp file path you remove it from the List. At the end, you can convert to an array again if desired.
Thanks

Yeah I missed the GetFileName() in my previous code. The reason for using toString() was that it didn't had the StartsWith() method. So, I thought it has to be casted to string.

My target machines contains XP SP2 users. So, I think I can't use FW3.5 as it requires SP3 or high.