ASP.Net menu databinding encoding problem

Posted by WtFudgE on Stack Overflow See other posts from Stack Overflow or by WtFudgE
Published on 2010-04-02T14:01:31Z Indexed on 2010/04/02 14:03 UTC
Read the original article Hit count: 546

Hi,

I have a menu where I bind data through:

XmlDataSource xmlData = new XmlDataSource();
        xmlData.DataFile = String.Format(@"{0}{1}\Navigation.xml", getXmlPath(), getLanguage());
        xmlData.XPath = @"/Items/Item";
        TopNavigation.DataSource = xmlData;
        TopNavigation.DataBind();

The problem is when my xml has special characters, since I use a lot of french words.

As an alternative I tried using a stream instead and using encoding to get the special characters, with the following code:

StreamReader strm = new StreamReader(String.Format(@"{0}{1}\Navigation.xml", getXmlPath(), getLanguage()), Encoding.GetEncoding(1254));
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(strm);

            XmlDataSource xmlData = new XmlDataSource();
            xmlData.ID = "TopNav";
            xmlData.Data = xDoc.InnerXml;
            xmlData.XPath = @"/Items/Item";
            TopNavigation.Items.Clear();
            TopNavigation.DataSource = xmlData;
            TopNavigation.DataBind();

The problem I'm having now is that my data doesn't refresh when I change the path where the stream gets read.

When I skip through the code it does, but not on my page.

So the thing is either, how do I get the data te be refreshed? Or (which is actually preferred) how do I get the encoding right in the first piece of code?

Help is highly apreciated!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about databinding