Solved

VB.NET DirectoryInfo Linq Query

Posted on 2010-09-02
8
743 Views
Last Modified: 2012-05-10
I am trying to get a list of files from a directory using LINQ.

The files names are along these lines:
google_FQDN.sm.xml (where FQDN is the actual FQDN)

tmpDomains is a comma-delimited list of FQDNs as they are pulled form an XMl file.  This pulls correctly.

The issue I am having is that nothing gets displayed.   I have verified that there are 6 files in the directory.    Each one of these files contains one of the FDQNs from tmpDomains.

I assume it is in my LINQ Query.

Please help?!?

Code to follow:

'Get List of domains from Common.BasePath & "Sites\CurrentSites.xml" based on SiteID
    'and do this query based on that returned string
    Dim objXml As New XmlDocument, tmpDomains As String
    Dim objNode As XmlNode
    With objXml
        .Load(Common.BasePath & "Sites\CurrentSites.xml")
        objNode = .SelectSingleNode("//Sites/Site[contains(@id,'" & AdminStuff.SiteID & "')]")
        tmpDomains = objNode.Attributes("domains").Value
    End With
    Dim tmpString As New StringBuilder, x As String, tmpCt As Long = 0
    Dim Query = From f In New DirectoryInfo(Common.BasePath & "Sitemaps\").GetFiles() _
                Select f.Name, f.CreationTime _
                Where "*" & Name & "*" Like tmpDomains
    tmpString.Append("<table width=""100%"" cellpadding=""0"" cellspacing=""0"" id=""auditTable"" class=""audit_table"">" & vbCrLf)
    tmpString.Append("  <thead>" & vbCrLf)
    tmpString.Append("      <tr>" & vbCrLf)
    tmpString.Append("          <th>File</th>" & vbCrLf)
    tmpString.Append("          <th>Posted</th>" & vbCrLf)
    tmpString.Append("      </tr>" & vbCrLf)
    tmpString.Append("  </thead>" & vbCrLf)
    tmpString.Append("  <tbody>" & vbCrLf)
    For Each Item In Query
        If tmpCt Mod 2 Then x = " style=""background:#EEE;""" Else x = ""
        tmpString.Append("  <tr>" & vbCrLf)
        tmpString.Append("      <td" & x & "><a href=""http://" & AdminStuff.SiteManaging & "/SiteMaps/" & Item.Name & """ target=""_blank"">" & Item.Name & "</a></td>" & vbCrLf)
        tmpString.Append("      <td" & x & ">" & Item.CreationTime & "</td>" & vbCrLf)
        tmpString.Append("  </tr>" & vbCrLf)
        tmpCt += 1
    Next
    tmpString.Append("  </tbody>" & vbCrLf)
    tmpString.Append("</table>" & vbCrLf)
    Response.Write(tmpString.ToString())
    tmpString = Nothing

Open in new window

0
Comment
Question by:kevp75
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 25

Author Comment

by:kevp75
ID: 33591433
side notes.  the actual file list is:

google_www.o7th.com.xml
google_www.07th.com.xml
google_www.o7thwebdesign.com.xml
google_www.07thwebdesign.com.xml
google_07th.com.xml
google_o7th.com.xml

and the actual tmpDomains value is:
o7th.com, 07th.com, o7thwebdesign.com, 07thwebdesign.com, www.o7th.com, www.07th.com, www.o7thwebdesign.com, www.07thwebdesign.com

what I am trying to do is display the file list based on if they exist in tmpDomains
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33591495
Looks like you might have your wildcards in the wrong place...

    Dim Query = From f In New DirectoryInfo(Common.BasePath & "Sitemaps\").GetFiles() _
                Select f.Name, f.CreationTime _
                Where Name Like "*" & tmpDomains & "*"

Wayne
0
 
LVL 25

Author Comment

by:kevp75
ID: 33595970
tried that way as well....same results
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33596171
How about something like this?

        Dim arrDomains() As String = tmpDomains.Replace(" ", "").Split(","c)
        Dim Query = From f In New IO.DirectoryInfo(Common.BasePath & "Sitemaps\").GetFiles() _
            Select f.Name, f.CreationTime Where arrDomains.Contains(Name.Replace("google_", "").Replace(".xml", ""))

Wayne
0
 
LVL 25

Author Comment

by:kevp75
ID: 33617545
i will try this out later today
0
 
LVL 25

Author Comment

by:kevp75
ID: 33619252
Ok,

    Dim arrDomains() As String = tmpDomains.Split(", ")
    Dim Query = From f In New DirectoryInfo(Common.BasePath & "Sitemaps\").GetFiles() _
            Select f.Name, f.CreationTime Where arrDomains.Contains(Name.Replace("google_", "").Replace(".xml", "")) _
            Or arrDomains.Contains(Name.Replace("sitemap_", "").Replace(".xml", ""))


works, however, it does not grab the www files
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 33621900
I created some xml files in a directory for testing, and this works fine for me....

        Dim tmpDomains As String = "o7th.com, 07th.com, o7thwebdesign.com, 07thwebdesign.com, www.o7th.com, www.07th.com, www.o7thwebdesign.com, www.07thwebdesign.com"

        Dim arrDomains() As String = tmpDomains.Replace(" ", "").Split(","c)
        Dim Query = From f In New DirectoryInfo("C:\ProgramData\SiteMaps\").GetFiles() _
                Select f.Name, f.CreationTime Where arrDomains.Contains(Name.Replace("google_", "").Replace(".xml", "")) _
                Or arrDomains.Contains(Name.Replace("sitemap_", "").Replace(".xml", ""))

        For Each v In Query
            MsgBox(v.Name)
        Next

Wayne
0
 
LVL 25

Author Closing Comment

by:kevp75
ID: 33653353
thank you
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question