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:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...