Monday, November 26, 2007

XML Serialization and Deserialization in .NET

/// <summary>
/// Serialize
/// </summary>
/// <param name="clientList">List of objects</param>
/// <returns>success/fail (bool)</returns>
private static bool SaveClientAttributes(List clientList)
{
    try
    {
        XmlSerializer serializer = new XmlSerializer(typeof(List));
        StreamWriter writer =
        new StreamWriter((Server.MapPath(string.Empty)) 
            + "\\ClientData.xml");
        List ClientList = new List();
        serializer.Serialize(writer, clientList);
        return true;
    }
    catch (Exception ex)
    {
        return false;
    }
 
}
/// <summary>
/// Deserialize
/// </summary>
/// <returns>List of objects</returns>
private static List LoadClientAttributes()
{
    List clientList = new List();
    try
    {
        XmlSerializer serializer = new XmlSerializer(typeof(List));
        FileStream fileStream =
        new FileStream((Server.MapPath(string.Empty))
            + "\\ClientData.xml", FileAccess.Read);
        clientList = (List)serializer.Deserialize(fileStream);
    }
    catch (Exception ex)
    {
        //Do nothing
    }
    return clientList;
}

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...