public FileEntry ReadFileConfiguration(string id)
{
string configurationPath = "conf.xml";
XDocument data = XDocument.Load(configurationPath);
return (from c in data.Descendants("file")
where (c.Attribute("Id") != null && c.Attribute("Id").Value.Equals(id))
select new FileEntry()
{
Name = c.Element("Name").Value,
Path = c.Element("Path").Value,
SheduledTime = Convert.ToDateTime(c.Element("SheduledTime").Value),
Size = (long)Convert.ToDouble( c.Element("Size").Value),
IsFolder = Convert.ToBoolean( c.Element("IsFolder").Value),
LastAccess = Convert.ToDateTime(c.Element("LastAccess").Value),
DoEncrypt = Convert.ToBoolean( c.Element("DoEncrypt").Value)
}).First();
}
Main program is:
main()
{
string id = "C:\\Users\\Radhesh\\Documents\\Visual Studio 2008\\Projects\\Rme\\Rme\\test.txt";
ReadFileConfiguration(id);
}
My XML page is:
<?xml version="1.0" encoding="utf-8" ?>
<Files>
<file Id="C:\Users\Radhesh\Documents\Visual Studio 2008\Projects\Rme\Rme\test.txt">
<Name>test.txt</Name>
<Path>C:\Users\Radhesh\Documents\Visual Studio 2008\Projects\Rme\Rme\test.txt</Path>
<IsFolder>False</IsFolder>
<DoEncrypt>True</DoEncrypt>
<Size>0</Size>
<LastAcess>7/9/2011 11:35:53 PM</LastAcess>
<SheduledTime>7/10/2011 1:59:20 PM</SheduledTime>
</file>
</Files>
My class:
class FileEntry
{
public string Name { get;set;}
public string Path { get; set; }
public bool IsFolder { get; set; }
public long Size { get;set; }
public DateTime LastAccess { get;set; }
public DateTime SheduledTime { get; set; }
public bool DoEncrypt { get; set; }
}
Please, can anyone help?
string configurationPath = @"C:\Users\Radhesh\Documents\Visual Studio 2008\Projects\Rme\Rme\conf.xml";.Load()will throw something other than NullRef when the path is wrong.