Click here to Skip to main content
Licence CPOL
First Posted 6 Jan 2010
Views 53,293
Downloads 2,701
Bookmarked 21 times

Remove Skype Chat History for Single Contact

By | 6 Jan 2010 | Article
A small C# utility to clear a single contact chat history, since Skype by default only deletes full chat history.
 
Part of The SQL Zone sponsored by
See Also
Skype Message Cleaner_setup

Introduction

I wanted to clear the Skype chat history for a single user, but Skype only allows you to clear the complete chat history, not a single user's contact history.

I searched for 3rd party tools on the net but nothing worked for me on Windows 7 / Skype 4.1

At the beginning, I knew nothing about how Skype stored chat history and just entered my username and password to login and chat with friends.

After spending a few hours asking Google many questions, I found that Skype was using the following SQLite database to store its messages.

System Drive:\<Current User’s application data folder>/Skype/<Skype username>/main.db

I tried to read it with SQLitespy, but it was a pain to find and clear messages each time. Then, decided to develop a small C# utility to clear a single contact chat history.

Using the Code

First of all, I had to find a method to deal with an SQLite database file using C#. This is where the System.Data.SQLite plays a role in my application. You may download it from http://sqlite.phxsoftware.com/

Reference System.Data.SQLite.dll (Located in C:\Program Files\SQLite.NET\bin\System.Data.SQLite.dll) to allow C# to deal with the SQLite database file.

Once I knew I was going to dirty my hands with development, I wanted to find the Skype username(s) to reach to the database file. In System Drive:\<Current User’s application data folder>/Skype/ folder, Other than Skype user folder(s), there are 3 folders that Skype use for its operations, “Content”, “My Skype received files” and “Pictures”. I wrote codes to read subfolders and filter-out those 3 Skype standard folders.

String sDirName = Environment.GetEnvironmentVariable("APPDATA") + @"\Skype";
String [] folders = Directory.GetDirectories(sDirName);
String[] names = new String[folders.Length-3];

            foreach (String fname in folders){
                String folder = fname.Replace(Environment.GetEnvironmentVariable("APPDATA") +
                    @"\Skype\", "");
                if (folder != "Content" && folder != "My Skype Received Files" && 
                    folder != "Pictures")
                {
                     usernamecb.Items.Add(folder);
                }
            }

The Usernamecb variable will be used to populate the dropdown box in the UI.

Based on the selected username we can reach the Skype message database (main.db) and read chat participants. Chat messages are stored in the "Messages" table.

The following code reads the database and fetches chat participnts (Contacts) who has messages in it.

database = Environment.GetEnvironmentVariable("APPDATA") + @"\Skype\" + SkypeUserName + 
    @"\main.db";
SQLiteConnection sqlite = new SQLiteConnection("data source=" + database);
SQLiteDataAdapter ad;
DataTable dt = new DataTable();

SQLiteCommand cmd;

sqlite.Open();

cmd = sqlite.CreateCommand();
cmd.CommandText = "select DISTINCT dialog_partner from Messages";
ad = new SQLiteDataAdapter(cmd);
ad.Fill(dt); //execute command
participants.DataSource = dt;
participants.ValueMember = "dialog_partner";

Where participants is a dropdown box in UI that displays chat participants.

When the user selects the participant from the dropdown box, the following SQL command deletes all messages for a selected participant from the database.

cmd = sqlite.CreateCommand();
cmd.CommandText = "delete from Messages Where dialog_partner = '" + participant + "'";
ad = new SQLiteDataAdapter(cmd);
ad.Fill(dt); //execute command

Then I realized that the database file is been locked while Skype is running. Therefore, I added code to terminate the Skype process when the program starts running, and starts up Skype again when the program closes.

// Terminate Skype
foreach (Process p in Process.GetProcesses(Environment.MachineName))
            {
                if (p.ProcessName.Equals("Skype"))
                {
                    p.Kill();
                }
          }
 
//Start Skype when the programe is exiting
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
            // open Skype again
            String program = Environment.GetEnvironmentVariable("ProgramFiles");
            try
            {

                System.Diagnostics.ProcessStartInfo psi =
                new System.Diagnostics.ProcessStartInfo(program + @"\Skype\Phone\Skype.exe");
                System.Diagnostics.Process.Start(psi);
            }
            catch (Exception ex){}
  }

When all the code comes together, it is a nice and painless tool for clearing a single user's chat history.

License

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

About the Author

lkgamage

Web Developer

Sri Lanka Sri Lanka

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionDitto to the program icon not showing PinmemberMember 90331398hrs 2mins ago 
QuestionWorked !! Pinmemberalps198122:48 24 May '12  
QuestionProgram Icon Not Appearing PinmemberDigit-Aria13:19 11 May '12  
Questionworks as advertised PinmemberW J21:13 23 Apr '12  
QuestionHello is this working for 5.5 skype? Pinmemberiplocker2:04 26 Nov '11  
GeneralMy vote of 4 PinmemberVUnreal9:48 17 Nov '11  
QuestionSkype message cleaner not working Pinmembertutingjhayr21:29 7 Sep '11  
AnswerRe: Skype message cleaner not working Pinmemberlkgamage5:01 8 Sep '11  
Questionfile does not download Pinmemberamangrewal0:24 7 Sep '11  
AnswerRe: file does not download Pinmemberlkgamage4:55 8 Sep '11  
NewsNew version of skype message cleaner. Pinmemberlkgamage14:31 17 Jul '10  
GeneralDoesn't work for me Pinmemberbowesmana17:41 13 Jun '10  
GeneralRe: Doesn't work for me Pinmemberbowesmana17:49 13 Jun '10  
GeneralRe: Doesn't work for me Pinmembersubstance9021:17 14 Jun '10  
GeneralRe: Doesn't work for me Pinmemberbowesmana0:00 28 Jun '10  
GeneralRe: Doesn't work for me Pinmemberlkgamage5:10 29 Jun '10  
GeneralRe: Doesn't work for me Pinmemberspeedxxx4:58 11 Apr '12  
GeneralAdd new feature - Remove partial skype chat history PinmemberLoic C22:16 7 Jun '10  
GeneralRe: Add new feature - Remove partial skype chat history Pinmemberlkgamage22:25 7 Jun '10  
GeneralRe: Add new feature - Remove partial skype chat history PinmemberLoic C5:18 30 Jun '10  
GeneralMy vote of 2 PinmemberAlejandro Xalabarder2:44 1 May '10  
Questioncant download PinmemberMember 295820510:55 19 Jan '10  
AnswerRe: cant download Pinmemberlkgamage0:09 20 Jan '10  
QuestionWhere backup is stord when checkbox is selected? PinmemberNiraj Parikh2:21 12 Jan '10  
AnswerRe: Where backup is stord when checkbox is selected? Pinmemberlkgamage6:54 12 Jan '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.5.120517.1 | Last Updated 6 Jan 2010
Article Copyright 2010 by lkgamage
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid