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
Ibrahim RashidPosted Jul 22, 2011, 1:31 AM
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.
VulpesPosted Jul 20, 2011, 2:04 PM
A RepaskyPosted Jul 20, 2011, 1:43 PM
So it will say:
VulpesPosted Jul 20, 2011, 12:03 PM
Console.WriteLine("\nPress any key to exit");
Console.ReadKey(true);
This should then prevent the console window closing until you press a key.
A RepaskyPosted Jul 20, 2011, 11:59 AM
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
A RepaskyPosted Jul 20, 2011, 11:09 AM
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
VulpesPosted Jul 20, 2011, 9:59 AM
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:
VulpesPosted Jul 20, 2011, 9:43 AM
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.
A RepaskyPosted Jul 20, 2011, 9:40 AM
arep
A RepaskyPosted Jul 20, 2011, 9:32 AM
name = (string)c.Attribute("Name"),
executable = (string)c.Attribute("Executable"),
arep
Jaganathan BantheswaranPosted Jul 20, 2011, 2:19 AM
What is the error here?
On which particular line you are getting ?