Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: StartupMode for Services Pin
Calla27-Sep-09 22:09
Calla27-Sep-09 22:09 
QuestionTranslation Of C# Class to XML And Vice versa Pin
Sachin Dubey27-Sep-09 19:59
Sachin Dubey27-Sep-09 19:59 
AnswerRe: Translation Of C# Class to XML And Vice versa Pin
Christian Graus27-Sep-09 20:24
protectorChristian Graus27-Sep-09 20:24 
GeneralRe: Translation Of C# Class to XML And Vice versa Pin
Sachin Dubey27-Sep-09 20:32
Sachin Dubey27-Sep-09 20:32 
GeneralRe: Translation Of C# Class to XML And Vice versa Pin
Christian Graus27-Sep-09 20:40
protectorChristian Graus27-Sep-09 20:40 
GeneralRe: Translation Of C# Class to XML And Vice versa Pin
Sachin Dubey27-Sep-09 20:44
Sachin Dubey27-Sep-09 20:44 
GeneralRe: Translation Of C# Class to XML And Vice versa Pin
0x3c027-Sep-09 21:04
0x3c027-Sep-09 21:04 
AnswerRe: Translation Of C# Class to XML And Vice versa Pin
freakyit27-Sep-09 23:27
freakyit27-Sep-09 23:27 
here i have an example for you to serialize and deserialize a class

/// <summary>
	    /// Method to convert a custom Object to XML string
	    /// </summary>
	    /// <param name="pObject">Object that is to be serialized to XML</param>
	    /// <returns>XML string</returns>
	    public string SerializeObject ( Object pObject, Type et )
	    {
	        try
	        {
	            String XmlizedString = null;
	            MemoryStream memoryStream = new MemoryStream ( );
	            XmlSerializer xs = new XmlSerializer ( et );
	            XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream, Encoding.UTF8 );
	            xmlTextWriter.Formatting = Formatting.Indented;
	            xmlTextWriter.Indentation = 4;
	            xs.Serialize ( xmlTextWriter, pObject );
	            memoryStream = ( MemoryStream ) xmlTextWriter.BaseStream;
	            XmlizedString = UTF8ByteArrayToString ( memoryStream.ToArray ( ) );
	            return XmlizedString;
	        }
	        catch ( Exception e )
	        {
	            System.Console.WriteLine ( e );
	            throw new Exception(e.Message,e);
	           // return null;
	        }
	    } 
	    
	    /// <summary>
	    /// Method to reconstruct an Object from XML string
	    /// </summary>
	    /// <param name="pXmlizedString"></param>
	    /// <returns></returns>
	    public Object DeserializeObject ( String pXmlizedString, Type e )
	    {
	        XmlSerializer xs = new XmlSerializer ( e );
	        MemoryStream memoryStream = new MemoryStream ( StringToUTF8ByteArray ( pXmlizedString ) );
	                
	        XmlTextWriter xmlTextWriter = new XmlTextWriter ( memoryStream , Encoding.UTF8 );
	 
	        return xs.Deserialize ( memoryStream );
	    }


and here the class how it looks.

[Serializable()]
[XmlRoot("Attrib")]
public class AttributeClass
{
    string sIdentifier;
    string sAlias;

    [XmlElement("Identifier")]
    public string Identifier {
        get { return sIdentifier; }
        set { sIdentifier = value; }
    }

    [XmlElement("Alias")]
    public string Alias {
        get { return sAlias; }
        set { sAlias = value; }
    }

}


and here the AttributeCollection as Class to serialize it..

	[Serializable()]
	[XmlRoot("AttribsList")]
	[XmlInclude(typeof(AttributeClass)),
	 XmlInclude(typeof(System.Collections.Generic.List<AttributeClass>))]
	public class AttribsList : System.Collections.Generic.List<AttributeClass>
	{
		/// <summary>
		/// Deserilizes the saved Xml AttribsList file to an object
		/// </summary>
		/// <param name="path">Path of the serilized XmlDataModelLayoutFile</param>
		/// <returns>XmlDataModelLayout object</returns>
		public static AttribsList LoadLayoutFromFile(string path)
		{
			try
			{
				string data_str = Core.SerializeHelper.ReadFromFile(path);
				Core.SerializeHelper sh = new Core.SerializeHelper();
				AttribsList list = (AttribsList)sh.DeserializeObject(data_str,typeof(AttribsList));
				
				return list;
			}
			catch
			{
				return null;
			}
		}
	
		/// <summary>
		/// Serilizes the Xml AttribsList object to file
		/// </summary>
		/// <param name="layout">XmlDataModelLayout object</param>
		/// <param name="path">FilePath to save object</param>
		public static void SaveLayout(AttribsList lst, string path)
		{
			Core.SerializeHelper sh = new Core.SerializeHelper();
			string data_str = sh.SerializeObject(lst,typeof(AttribsList ));
			
			Core.SerializeHelper.SaveToFile(path,data_str);
		}
       }
}

GeneralRe: Translation Of C# Class to XML And Vice versa Pin
Sachin Dubey27-Sep-09 23:32
Sachin Dubey27-Sep-09 23:32 
QuestionData Grid view search Pin
anishkannan27-Sep-09 19:45
anishkannan27-Sep-09 19:45 
AnswerRe: Data Grid view search Pin
Sachin Dubey27-Sep-09 19:56
Sachin Dubey27-Sep-09 19:56 
AnswerRe: Data Grid view search Pin
Mycroft Holmes27-Sep-09 22:14
professionalMycroft Holmes27-Sep-09 22:14 
GeneralRe: Data Grid view search Pin
anishkannan27-Sep-09 23:39
anishkannan27-Sep-09 23:39 
QuestionWebbrowser DocumentText errors Pin
discreetz27-Sep-09 19:16
discreetz27-Sep-09 19:16 
AnswerRe: Webbrowser DocumentText errors Pin
Richard MacCutchan27-Sep-09 21:52
mveRichard MacCutchan27-Sep-09 21:52 
Questionfile search Pin
Member 59031027-Sep-09 19:12
Member 59031027-Sep-09 19:12 
AnswerRe: file search Pin
Calla27-Sep-09 19:31
Calla27-Sep-09 19:31 
AnswerRe: file search Pin
OriginalGriff27-Sep-09 22:10
mveOriginalGriff27-Sep-09 22:10 
GeneralRe: file search Pin
Calla27-Sep-09 23:56
Calla27-Sep-09 23:56 
GeneralRe: file search Pin
vivasaayi28-Sep-09 4:06
vivasaayi28-Sep-09 4:06 
QuestionHow to create a folder in any drive by C# .Net Command Pin
Rahad Rahman27-Sep-09 17:12
professionalRahad Rahman27-Sep-09 17:12 
AnswerRe: How to create a folder in any drive by C# .Net Command Pin
PIEBALDconsult27-Sep-09 17:17
mvePIEBALDconsult27-Sep-09 17:17 
AnswerRe: How to create a folder in any drive by C# .Net Command Pin
Dave Kreskowiak27-Sep-09 18:09
mveDave Kreskowiak27-Sep-09 18:09 
QuestionHTML-to-XML Library in C# Pin
sheateng27-Sep-09 15:31
sheateng27-Sep-09 15:31 
AnswerRe: HTML-to-XML Library in C# Pin
Not Active27-Sep-09 15:57
mentorNot Active27-Sep-09 15:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.