P
pei_world
I have followed a example from a book exactly, but it seems not working at
all.
can anyone tell me what is going on?
========= Global.asax.cs ============
public static Entry LoadEntry(String filename)
{
//construct the path
String filepath = XMLFilePath + "\\" + filename;
FileStream f = null;
Entry newEntry;
try
{
//open the file
f = new FileStream(filepath,FileMode.Open);
//create a serializer...
XmlSerializer serializer = new XmlSerializer(typeof(Entry));
newEntry = (Entry)serializer.Deserialize(f);
}
finally
{
//close the file
f.Close();
}
//retrun the entry..
return newEntry;
}
====== default.aspx.cs =======
//loading entry from xml file
Entry entry = Global.LoadEntry("address.xml");
this.lblCatalog.Text = entry.Catalog;
this.lblName.Text = entry.Name;
this.lblAddress.Text = entry.Address;
===== address.xml ========
<?xml version="1.0" encoding="utf-8" ?>
<Addr xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Catalog>novel</Catalog>
<Name>Sina</Name>
<Web>http://www.sina.com.cn</Web>
</Addr>
all.
can anyone tell me what is going on?
========= Global.asax.cs ============
public static Entry LoadEntry(String filename)
{
//construct the path
String filepath = XMLFilePath + "\\" + filename;
FileStream f = null;
Entry newEntry;
try
{
//open the file
f = new FileStream(filepath,FileMode.Open);
//create a serializer...
XmlSerializer serializer = new XmlSerializer(typeof(Entry));
newEntry = (Entry)serializer.Deserialize(f);
}
finally
{
//close the file
f.Close();
}
//retrun the entry..
return newEntry;
}
====== default.aspx.cs =======
//loading entry from xml file
Entry entry = Global.LoadEntry("address.xml");
this.lblCatalog.Text = entry.Catalog;
this.lblName.Text = entry.Name;
this.lblAddress.Text = entry.Address;
===== address.xml ========
<?xml version="1.0" encoding="utf-8" ?>
<Addr xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Catalog>novel</Catalog>
<Name>Sina</Name>
<Web>http://www.sina.com.cn</Web>
</Addr>