11
Reply

LINQ not working

A Repasky

A Repasky

Jul 19 2011 5:16 PM
2.3k
My LINQ code is not working.  I used this many times before, but in this program it is not working.  Here is my code:

    static class AutoExtract
  {
 public static string name = null;
  public static string executable = null;
  public static string path = null;

 
  public static void Main()
  {
  try
  {
  //Get Application Path
  path = Output_Files.GetPath();
  Console.WriteLine(path);
 
  //Get XML Data
  XDocument inputDoc = XDocument.Load(path + @"\AutoExtract.xml");
  Console.WriteLine(inputDoc.ToString());

 
  // Query the data
  var q = from c in inputDoc.Descendants("AutoExtract")
  select new
  {
  name = (string)c.Attribute("Name"),
  executable = (string)c.Attribute("Executable"),
  };

 
  foreach (var item in q)
  {
  name = item.name;
  executable = item.executable;
  Console.WriteLine("xxx" + item.name + "xxx" + item.executable + "xxx");

 
  //Run process on program
  ProcessExtract();
  }

 Here is my XML file:

<AutoExtract>
 <Extract Name="WeeklyExtracts" Executable="C:\WeeklyExtracts\WeeklyExtracts\bin\Debug\WeeklyExtracts.exe">
 </Extract>
</AutoExtract>


Does anyone know why this does not work?  And it worked with other programs!

Thanks ahead of time.

arep

Answers (11)