Reading a XML file from IsolatedStorage ?
hi.
i'm reading xml file has been stored in isolatedstorage
.
exception occurring
.
root element missing
i'm dead sure there isn't troubles in xml file, don't know result of exception
guide me ?
thank you.
snippet code :
using (isolatedstoragefile isostore = isolatedstoragefile.getuserstoreforapplication()) { . . . string settingfilepath = "codecolorizer\\setting.xml"; using (isolatedstoragefilestream isostream = new isolatedstoragefilestream(settingfilepath, filemode.create, isostore)) { isostream.position = 0; xmlreader xmlreader; xmlreader = xmlreader.create(isostream); //moves reader root element. xmlreader.movetocontent();//exception occurring here string value; while (xmlreader.read()) { switch (xmlreader.nodetype) { case xmlnodetype.element: { if (xmlreader.name == "isvb") { value = (string)xmlreader.readcontentas(type.gettype("string"), null); if (value == "true") { this.isvb.ischecked = true; this.iscsharp.ischecked = false; } else if (value == "false") { this.isvb.ischecked = false; this.iscsharp.ischecked = true; } } else if (xmlreader.name == "iscsharp") { value = (string)xmlreader.readcontentas(type.gettype("string"), null); if (value == "true") { this.isvb.ischecked = false; this.iscsharp.ischecked = true; } else if (value == "false") { this.isvb.ischecked = true; this.iscsharp.ischecked = false; } } else if (xmlreader.name == "isstriped") { value = (string)xmlreader.readcontentas(type.gettype("string"), null); if (value == "true") { this.isstriped.ischecked = true; } else if (value == "false") { this.isstriped.ischecked = false; } } else if (xmlreader.name == "haslinenumber") { value = (string)xmlreader.readcontentas(type.gettype("string"), null); if (value == "true") { this.haslinenumber.ischecked = true; } else if (value == "false") { this.haslinenumber.ischecked = false; } } else if (xmlreader.name == "adddefaultstyleswithinpretags") { value = (string)xmlreader.readcontentas(type.gettype("string"), null); if (value == "true") { this.adddefaultstyleswithinpretags.ischecked = true; } else if (value == "false") { this.adddefaultstyleswithinpretags.ischecked = false; } } else if (xmlreader.name == "cssclassname") { value = (string)xmlreader.readcontentas(type.gettype("string"), null); this.cssclassname.text = value; } else if (xmlreader.name == "addpretag") { value = (string)xmlreader.readcontentas(type.gettype("string"), null); if (value == "true") { this.addpretag.ischecked = true; } else if (value == "false") { this.addpretag.ischecked = false; } } else if (xmlreader.name == "addbgcolor") { value = (string)xmlreader.readcontentas(type.gettype("string"), null); if (value == "true") { this.addbgcolor.ischecked = true; } else if (value == "false") { this.addbgcolor.ischecked = false; } } else if (xmlreader.name == "textboxcolor") { value = (string)xmlreader.readcontentas(type.gettype("string"), null); this.textboxcolor.text = value; } break; } } } } }
thnk you, didn't use linq.
i've done :
using (isolatedstoragefile isostore = isolatedstoragefile.getuserstoreforapplication())
{
.
.
.
string settingfilepath = "codecolorizer\\setting.xml";
using (isolatedstoragefilestream isostream = new isolatedstoragefilestream(settingfilepath, filemode.open, isostore))
{
isostream.position = 0;
xmlreader xmlreader;
xmlreader = xmlreader.create(isostream);
//moves reader root element.
xmlreader.movetocontent();
string value;
while (xmlreader.read())
{
switch (xmlreader.nodetype)
{
case xmlnodetype.element:
{
if (xmlreader.name == "isvb")
{
value = xmlreader.readelementcontentasstring();
if (value == "true") { this.isvb.ischecked = true; this.iscsharp.ischecked = false; }
else if (value == "false") { this.isvb.ischecked = false; this.iscsharp.ischecked = true; }
}
else if (xmlreader.name == "iscsharp")
{
value = xmlreader.readelementcontentasstring();
if (value == "true") { this.isvb.ischecked = false; this.iscsharp.ischecked = true; }
else if (value == "false") { this.isvb.ischecked = true; this.iscsharp.ischecked = false; }
}
else if (xmlreader.name == "isstriped")
{
value = xmlreader.readelementcontentasstring();
if (value == "true") { this.isstriped.ischecked = true; }
else if (value == "false") { this.isstriped.ischecked = false; }
}
else if (xmlreader.name == "haslinenumber")
{
value = xmlreader.readelementcontentasstring();
if (value == "true") { this.haslinenumber.ischecked = true; }
else if (value == "false") { this.haslinenumber.ischecked = false; }
}
else if (xmlreader.name == "adddefaultstyleswithinpretags")
{
value = xmlreader.readelementcontentasstring();
if (value == "true") { this.adddefaultstyleswithinpretags.ischecked = true; }
else if (value == "false") { this.adddefaultstyleswithinpretags.ischecked = false; }
}
else if (xmlreader.name == "cssclassname")
{
value = xmlreader.readelementcontentasstring();
this.cssclassname.text = value;
}
else if (xmlreader.name == "addpretag")
{
value = xmlreader.readelementcontentasstring();
if (value == "true") { this.addpretag.ischecked = true; }
else if (value == "false") { this.addpretag.ischecked = false; }
}
else if (xmlreader.name == "addbgcolor")
{
value = xmlreader.readelementcontentasstring();
if (value == "true") { this.addbgcolor.ischecked = true; }
else if (value == "false") { this.addbgcolor.ischecked = false; }
}
else if (xmlreader.name == "textboxcolor")
{
value = xmlreader.readelementcontentasstring();
this.textboxcolor.text = value;
}
break;
}
}
}
}
}
Silverlight > Programming Silverlight with .NET – General
Comments
Post a Comment