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:
Does anyone know why this does not work? And it worked with other programs!
Thanks ahead of time.
arep

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jul 19, 2011, 10:19 PM EDT
What is the error here?
On which particular line you are getting ?
A RepaskyRank #8,108 · 228 reputationPosted Jul 20, 2011, 5:32 AM EDT
name = (string)c.Attribute("Name"),
executable = (string)c.Attribute("Executable"),
arep
A RepaskyRank #8,108 · 228 reputationPosted Jul 20, 2011, 5:40 AM EDT
arep
VulpesRank #55 · 29.2K reputationPosted Jul 20, 2011, 5:43 AM EDT
Curiously, XDocument.Load doesn't throw an exception if the file can't be found.
I'd try temporarily hard-coding the path to see if it works then.
VulpesRank #55 · 29.2K reputationPosted Jul 20, 2011, 5:59 AM EDT
Although the documentation doesn't say that it throws an exception if the file can't be found, I've just tried the code and it does in fact do so.
I think the problem actually lies with the query itself which should be:
A RepaskyRank #8,108 · 228 reputationPosted Jul 20, 2011, 7:09 AM EDT
You are correct. I was using the wrong Element, which I did not notice. In the other programs I have used the correct Element and in this one I used the wrong one. It seems to be working. This program was written to execute other programs, so that the other programs would not have to me scheduled. They are all batch console programs. Instead of running 20 or so programs and schedule them this program is scheduled and the other programs are run from this. So I still have to see if this is working, but not at least it seems to be executing the LINQ correctly.
So thanks for the help. I am going to leave this open until I see if it does what it is supposed to.
arep
A RepaskyRank #8,108 · 228 reputationPosted Jul 20, 2011, 7:59 AM EDT
I have another question. When the other program under this run, I write out some console messages. Now since they are running below this program, I do not see them. Is there a way to see them?
Like I said the only thing this program does is run other console programs so that instead of 20 programs running and being scheduled, only this one program is scheduled.
So how do I see the lower console messages? Or do I have to repost this message again with a new topic?
arep
VulpesRank #55 · 29.2K reputationPosted Jul 20, 2011, 8:03 AM EDT
Console.WriteLine("\nPress any key to exit");
Console.ReadKey(true);
This should then prevent the console window closing until you press a key.
A RepaskyRank #8,108 · 228 reputationPosted Jul 20, 2011, 9:43 AM EDT
So it will say:
But since this Program A (and others that do the same console writing) is running under the another Program 1
process that runs Program A, you do not see the console.
I am not sure if there is a solution for this. Technically it would have to be passed up to the process,
Program 1 that is running Program A and then be displayed by the Program 1.
I hope this is not confusing. I tried to explain the best I can.
Thanks,
arep
VulpesRank #55 · 29.2K reputationPosted Jul 20, 2011, 10:04 AM EDT
Ibrahim Rashid69 reputationPosted Jul 21, 2011, 9:31 PM EDT
var q = from c in inputDoc.Descendants("AutoExtract")
select new
{
name = (string)c.Attribute("Name"),
executable = (string)c.Attribute("Executable"),
};
I am not sure, but i have seen a comma(,) after executable = (string)c.Attribute("Executable"), which may be a problem.
Check out.