views:

169

answers:

4

I'm trying to get this sitemap class working.

It appears to use LINQ, which I've never used, but half the fun of programming is learning new stuff!

My problem is that I'm getting compile errors where the LINQ code is. VS just doesn't recognize it. I've a reference to system.data.linq, I've an imports system.data.linq, but still where the code reads, "Dim folders = From o In Directory.GetDirectories...", it's telling me "End of statement expected."

What am I missing in wiring this thing up so that I can use LINQ? My framework is 2.0.5. Is LINQ simply unavailable to me in 2? If so, why is system.data.linq in my GAC?

Here's the code:

    Private Sub AddFolders(ByVal parentNode As SiteMapNode)
Dim folders = From o In Directory.GetDirectories(HttpContext.Current.Server.MapPath(parentNode.Key)) _
Let dir = New DirectoryInfo(o) _
Where Not Regex.Match(dir.Name, ExcludedFolders).Success _
Select New ()

        For Each item In folders
            Dim folderUrl As String = parentNode.Key + item.DirectoryName
            Dim folderNode As New SiteMapNode(Me, folderUrl, Nothing, item.DirectoryName, item.DirectoryName)

            AddNode(folderNode, parentNode)
            AddFiles(folderNode)
        Next
    End Sub

Thanks y'all. Stack Overflow rocks.

+3  A: 
Dim folders = From o In Directory.GetDirectories(HttpContext.Current.Server.MapPath(parentNode.Key)) _
Let dir = New DirectoryInfo(o) _
Where Not Regex.Match(dir.Name, ExcludedFolders).Success _
Select dir

EDIT: actually you can't use Linq in .NET 2.0, at least not without a few tweaks... However, code using Linq and compiled with the .NET 3.5 compiler can be run on a .NET 2.0 runtime, using LinqBridge

Thomas Levesque
Thank you very much. That LinqBridge looks pretty spiffy.
aape
+2  A: 

You have to target 3.5 (Visual Studio 2008) to use linq.

Will
3.5 actually...
Thomas Levesque
Already edited.
Will
Thank you very much.
aape
+2  A: 

You can use LINQ with .NET 2.0, according to this link (I didn't test it personally). You'll need Visual Studio 2008 though...

If it's at all possible, I'd suggest that you upgrade to .NET 3.5, unless you want to wait for the soon-to-be-released .NET 4.0 :-)

Meta-Knight
Thank you for the information and link.
aape
+2  A: 

If you're targeting the .NET Framework 2, you can get LINQ working...with a little extra effort.

The easiest way to get things moving quickly is to download LINQBridge which provides a LINQ implementation for Framework 2.

As for why you're seeing System.Data.Linq in the GAC...sounds like you have .NET 3.5 installed side by side with .NET 2.0

Justin Niessner
"...sounds like you have .NET 3.5 installed side by side with .NET 2.0"Thanks. That would have bugged me all day wondering about that.
aape