Please i need help with this error. I am creating a web blog where i will store xml files in a folder called entries, the page that will display the xml files i named as hotelweblog.aspx, and the page that will enter the data to create new xml files in the entries folder i named as Edit.aspx. I can create new xml files with the edit page but when displaying in the hotelweblog page it returns the below error. Mean while when i open my xml files in IE it opens without error but i dont know why it wont just display.
Exception Details: System.Xml.XmlException: The data at the root level is invalid. Line 1, position 1.
Source Error:
Line 81: FileStream file = new FileStream(filepath, FileMode.Open);
Line 82: XmlSerializer serializer = new XmlSerializer(typeof(Entry));
Line 83: Entry newEntry = (Entry)serializer.Deserialize(file);
Line 84: file.Close();
Line 85: newEntry.Timestamp = new FileInfo(filepath).LastWriteTime;
Source File: c:\inetpub\wwwroot\hotelweb\global.asax.cs Line: 83
Stack Trace:
[XmlException: The data at the root level is invalid. Line 1, position 1.]
System.Xml.XmlTextReader.ParseRoot() +295
System.Xml.XmlTextReader.Read() +127
System.Xml.XmlReader.MoveToContent() +75
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read4_Entry() +16
[InvalidOperationException: There is an error in XML document (0, 0).]
System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
System.Xml.Serialization.XmlSerializer.Deserialize (XmlReader xmlReader, XmlDeserializationEvents events)
System.Xml.Serialization.XmlSerializer.Deserialize (Stream stream)
HotelWeb.Global.LoadEntry(String filename) in c:\inetpub\wwwroot\hotelweb\global.asax.cs:83
HotelWeb.Global.LoadAllEntries() in c:\inetpub\wwwroot\hotelweb\global.asax.cs:97
HotelWeb.HotelWebLog.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\hotelweb\hotelweblog.aspx.cs:31
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
My Global.aspx i have checked so many times and found no errors. below is my global.aspx.
public static Entry LoadEntry(String filename)
{
String filepath = EntryFilePath + "\\" + filename;
FileStream file = new FileStream(filepath, FileMode.Open);
XmlSerializer serializer = new XmlSerializer(typeof(Entry));
Entry newEntry = (Entry)serializer.Deserialize(file);
file.Close();
newEntry.Timestamp = new FileInfo(filepath).LastWriteTime;
newEntry.Filename = filename;
return newEntry;
}
public static Entry[] LoadAllEntries()
{
DirectoryInfo entryFolder = new DirectoryInfo(EntryFilePath);
FileInfo[] files = entryFolder.GetFiles();
Entry[] entries = new Entry[files.Length];
int index = files.Length -1;
foreach(FileInfo file in files)
{
entries[index] = LoadEntry(file.Name);
index--;
}
return entries;
}
Please i need this help if anyone can. Thanks
|