|
-
Nov 28th, 2011, 04:05 AM
#8
Re: Remove temp document
 Originally Posted by jmcilhinney
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:
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.
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|