Click here to Skip to main content
13,049,814 members (75,184 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 29 Jan 2006

Combine multiply MSN chat histories into whole one

, 4 Feb 2006
Rate this:
Please Sign up or sign in to vote.
It can combine multply MSN chat histories into whole one and guide you how to use XML.
Sample Image - CombineMSNChats.jpg <!------------------------------- STEP 3 ---------------------------><!-- Add the article text. Please use simple formatting (


etc) -->


Generally, many people maybe use MSN Messenger in different places, such as home, office, and other places. it will result in a problem that multiply MSN chat histories are in difference places. It is good if these copies of MSN chats can be combined into one. But MSN Messenger doesn't support this function, So I program it myself. This tool is programming in C# using .NET framework 1.1.

The Method To Implement It

We must get know the MSN chat history before we do it. As we know, the chat is saved in XML file. Due to this, we should know the format of the XML file. The XML file can be opened in Editor tools, such as UltraEdit, XMLSpy. OK.I'll show a picture here to get know the formats for MSN chat file. I use XMLSpy to operate on it. because XMLSpy is a very excellent tool on XML.

First, see the picture below:

  Sample screenshot

In this picture, we can find that MSN chat file has a root element <Log>, and many child nodes—one MSN message item --are attached to the root element.<Log> element has 2 attributes, FirstSeesionID and LastSessionID, which indicate the session.

 Obviously, there are 3 types of MSN message. Actually, there are 5 types:

  • Common Message
  • Invitation Message
  • InvitationResponse Message
  • Leave Message
  • Join Message

Different type of MSN messages has different formats. I’ll demonstrate it as following.

  • Common Message

Let’s take a look at a Common Message example.

<Message Date="2005-11-6" Time="15:16:17" 

DateTime="2005-11-06T07:16:17.339Z" SessionID="1">
<User FriendlyName="From User"/> </From>

<To><User FriendlyName="To User "/> </To>

<Text Style="font-family:MS Shell Dlg; color:#000000; ">Text </Text>


 You can get the schema of this easily. Refine it:

<Message Date="" Time="" DateTime="" SessionID="">


A common message includes 3 parts: From User, To user, and Message text.

  • Invitation Message

We can use the same way to fetch the format.

<Invitation Date="" Time="" DateTime="" SessionID="">

<From> <User FriendlyName=""/>
<User FriendlyName=" "/>


So it also includes 3 parts: From User, Application (Or File), Text.

  • InvitationResponse Message
<InvitationResponse Date="" Time="" 
DateTime="" SessionID<From>
<User FriendlyName=" "/>From><Application> 
Style="<SPAN lang=EN-US style="FONT-SIZE: 12pt">"> 

Same Invitation Message

  • Leave Message
<Leave Date="" Time="" DateTimne="" SessionID="">
<User FriendlyName="">
<Text Style=""></Text>

It includes 2 parts: User and Text.

  • Join Message

Same as Leave Message.

After we know the format of MSN chat file, we can get each message from multiply copies of MSN chat. Since each message has unique date time and session, we can sort the MSN messages by them.

Then save these sorted MSN message into a container, such as ArrayList, hashtable and SortedList in .NET framework.

 Finally, save these sorted MSN messages in a file in XML Format.

 In conclusion, there are 4 steps to it

  •   Step 1: Read the copies of MSN chat file and parse the message.
  •   Step 2: Sort MSN messages
  •   Step 3: Combine these copies of MSN message.
  •   Step 4: Save the sorted MSN message to a XML file.


Generate Session ID

  Because the MSN message come from different files, so the Session ID maybe are same. How to generate the session ID? As we know, the date time of each message is different. We can use it to do this.

   In the original MSN chat file, previous and current MSN message maybe have same session ID, if so, the session of them should be same,. If not so, the current message should be previous message’s session ID +1.


How to implement it.

 I use C# to do this. In .NET framework, it is easy to operate on XML file.

 I define 5 classes to represent the types MSN messages. They are:

  • MSNInvitationMessageInfo

To represent MSN invitation message.

  • MSNInvitationResponseMesssageInfo

To represent MSN invitation response message.

  • MSNJoinMessageInfo

To represent MSN join messages.

  • MSNLeaveMessageInfo

To represent leave message.

  • MSNMessageInfo

To represent common message.

These 5 classes all inherit from a base class: MSNBaseMessage.

Meanwhile, I also declare other 3 class:

  • MSNChatDocument

Represent a MSN chat history file.

It includes 3 important properties:

             FirstSessionID—First Session ID

LastSessionID—Last Session Id

MSNMessages—All MSN messages from a MSN chat history file

  • MSNDocumentCombine

Combine multiply copies of MSN histories.

It has 4 important properties:

                   FirstDocumentPath—The first MSN history file path.

                  SecondDocumentPath—The second MSN history file path.

                  SavedDocumentPath—The path to save the combined MSN history

                 XSLFilePathSrc—XSL file path.

And a method—Combine()—to combine MSN files.

  • MSNSession

Generate Session ID.

To get the overview, see the below picture

Source Code

Let’s have a glance at the UI entry

MSNDocumentCombine chatDoc=new MSNDocumentCombine();
for(int index=2;index&alt;listFiles.Items.Count;index++)

Create a MSNDocumentCombine object, then set value to its properties, finally call Combine() methods to implement it.

For the details to combine. See the below code:

//Load the first document
firstDoc=new MSNChatDocument(this.FirstDocumentPath);
//Load the second document
secondDoc=new MSNChatDocument(this.SecondDocumentPath);

//Combine the 2 files records
SortedList sl1=firstDoc.MSNMessages;
SortedList sl2=secondDoc.MSNMessages;
 for(int index=0;index&alt;sl1.Count;index++)
//save to new XML file

First, load the files, and parse the MSN messages.then combine 2 MSN messages source. Finally save these message.

How to save the message? I have mentioned that there are 5 types MSN messages and 5 MSN message format. so we can save it according to the format.

Take Commmon MSN Message as an example:

/// <summary>
// Build common message.
/// </summary>
/// <param name="sw">Stream witter to XML file</param>
/// <param name="message">The common message.</param>
private void BuildGeneralMessage(StreamWriter sw,MSNMessageInfo message)
sw.WriteLine("<Message Date=\""+message.DateTimeOn.ToShortDateString() 
+"\" Time=\""+ message.DateTimeOn.ToShortTimeString()+"\" DateTime=\""

+"Z\" SessionID=\""+message.SessionID+"\">");
//From User
for(int index=0;index<message.FromUsers.Count;index++)
 sw.WriteLine("<User FriendlyName=\""+

//To Users
for(int index=0;indexlt;message.ToUsers.Count;index++)
sw.WriteLine("<User FriendlyName=\""+ToXmlString((((MSNUserInfo)
sw.Write("<Text ");


First, build Message entity, then create From user, To user and Message text. So other types are .

How to generate Session ID? We can get the code from class MSNSession.

int nSessionID=1;
int nOldSessionID=0;

//There are more than 1 MSN messages
for(int index=0;index<m_slSrc.Count;index++)
  me=new MSNBaseMessage();
  me=m_slSrc.GetByIndex(index) as MSNBaseMessage;

   pre=new MSNBaseMessage();         
   pre=( MSNBaseMessage)(m_slSrc.GetByIndex(index-1));			



We must know the Format of MSN chat history. Once get it, it will become easy to do it. And during it, It is important to read, parse, and save the MSN messages. In additional, How to generate the session ID also is important. XSL file is the style of MSN message. Please DO copy it to the MSN history file.


  •  2006-01-30 The initial version.
  •  2006-02-05  Updated. Update the generation of session ID


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
China China
I'm from Shanghai, China, and working on a company Tangerine Technology. Like Softwate development,open source, enterprise development. In addition, I spend much time translating Enlish book , technical articles.
I like reading book, sports and tour, and listening music. the feeling is so good!

You may also be interested in...


Comments and Discussions

GeneralAbout "InvatationResponse", Serious ERROR to make me lose or damage my messages [modified] Pin
Harly14-Feb-10 13:56
memberHarly14-Feb-10 13:56 
Generalbug with quotes in nicknames Pin
852y3agnna14-Jun-06 13:24
member852y3agnna14-Jun-06 13:24 
QuestionTime Stamp Not Working? Pin
Coke355mL8-Feb-06 3:23
memberCoke355mL8-Feb-06 3:23 
AnswerRe: Time Stamp Not Working? Pin
confach8-Feb-06 14:07
memberconfach8-Feb-06 14:07 
GeneralRe: Time Stamp Not Working? Pin
Coke355mL20-Feb-06 13:59
memberCoke355mL20-Feb-06 13:59 
GeneralRe: Time Stamp Not Working? Pin
confach20-Feb-06 14:24
memberconfach20-Feb-06 14:24 
GeneralUpdate this article Pin
confach5-Feb-06 3:14
memberconfach5-Feb-06 3:14 
QuestionGood job! Pin
flair5-Feb-06 2:38
memberflair5-Feb-06 2:38 
AnswerRe: Good job! Pin
confach5-Feb-06 2:51
memberconfach5-Feb-06 2:51 
GeneralRe: Good job! Pin
flair5-Feb-06 14:54
memberflair5-Feb-06 14:54 
GeneralRe: Good job! Pin
confach5-Feb-06 15:01
memberconfach5-Feb-06 15:01 
GeneralRe: Good job! Pin
confach5-Feb-06 22:36
memberconfach5-Feb-06 22:36 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 4 Feb 2006
Article Copyright 2006 by confach
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid