Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a webservice that will contact a SQL database. This database connection string will need to contain a username and password. Ass this password must be changed every 6 months we have decided to keep this data in an xml file on the web service so that it can be dynamically added to the connection string.

So i have the xml file that contains this data:

XML
<pre><AllUsers>
  <user>
    <ID>ID</ID>
    <Password>NewPassword</Password>
  </user>
</AllUsers>


and i have the code needed to deserialize this into an existing class called user.

C#
public static List<T> RetrieveFromXML<T>(string filename, string root)
        {
            // Declare an object variable of the type to be deserialized.
            List<T> t;
            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                XmlSerializer ser = new XmlSerializer(typeof(List<T>), new XmlRootAttribute(root));
                t = (List<T>)ser.Deserialize(fs);
            }
            return t;
        }


so to call this function i must put:

C#
List<user> account = RetrieveFromXML<user>(@"AccountDetails.xml","AllUsers");


However i get an error saying the AccountDetails.xml doesnt exist or isnt situated wherever it is looking.

Should this file be an embedded resource? content? and what can i use to get the correct position of this file in the assembly?

Many thanks
Posted
Comments
ZurdoDev 5-Dec-12 10:07am    
You should be able to give the path to the file. Make sure the permissions are correct.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900