Click here to Skip to main content
Click here to Skip to main content

Remove Skype Chat History for Single Contact

, 17 Feb 2013
Rate this:
Please Sign up or sign in to vote.
A small C# utility to clear a single contact chat history, since Skype by default only deletes full chat history.

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. 

Revision (2013/02/18) 


1. Updated utility to working with Skype 5.1 and later folder structure while searching skype user accounts

2. Application will automatically remove conversation from recent conversation tab

3. Published setup files for both 32bit and 64 systems 

 

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
No Biography provided

Comments and Discussions

 
BugException (Windows 8) PinmemberNavik16-Jul-14 8:06 
QuestionFix for Deleting completely Pinmemberdinhthuan_bk8819-May-14 18:42 
Questioncant run PinmemberMember 295820514-Apr-14 9:10 
QuestionRe: cant run Pinmemberhubertsk22-Apr-14 1:35 
Questioncan't run PinmemberMcClausky8-May-13 3:25 
BugDoesn't delete ALL messages Pinmemberskhanvilkar@hpiinc.com28-Apr-13 4:47 
QuestionSelecting a date range still erased ENTIRE persons history [modified] PinmemberMember 964919527-Apr-13 3:42 
GeneralMy vote of 4 Pinmemberpakssg14-Apr-13 23:27 
Questionhelp .NET ERROR PinmemberMember 98835866-Mar-13 22:04 
AnswerRe: help .NET ERROR PinmemberSergey Kasatikoff11-Mar-13 18:55 
Questiondate interval Pinmemberapabox22-Feb-13 8:02 
GeneralMy vote of 2 Pinmemberlankymart13-Feb-13 3:48 
GeneralRe: My vote of 2 PinmemberPavloD14-Feb-13 21:59 
GeneralRe: My vote of 2 Pinmemberlkgamage18-Feb-13 2:53 
GeneralRe: My vote of 2 PinmemberPavloD18-Feb-13 4:22 
GeneralRe: My vote of 2 Pinmemberlkgamage18-Feb-13 4:42 
GeneralRe: My vote of 2 PinmemberPavloD19-Feb-13 3:41 
QuestionWorks like a Charm Pinmemberjuan luis vera16-Jan-13 13:43 
Great small app. I installed it and worked like a charm. (windows 7 home and skype 6.1). Make sure you guys download the latest version of this app: http://gl360.net/skype/Skype_Message_Cleaner_1.2.zip
AnswerRe: Works like a Charm PinmemberPavloD30-Jan-13 5:17 
GeneralMy vote of 5 PinmemberNeobycajnyy16-Jan-13 3:53 
BugCould not load file or assembly 'System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'System.Data.SQLite, Versi Pinmemberumutjunk9-Jan-13 21:24 
GeneralRe: Could not load file or assembly 'System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format. File name: 'System.Data.SQLite, V Pinmemberlankymart13-Feb-13 3:46 
QuestionOk got the bug sorted PinmemberMember 970732423-Dec-12 2:09 
BugNew version not working either PinmemberDavid Horwitz18-Dec-12 19:24 
QuestionNew Release Pinmemberlkgamage4-Dec-12 2:24 
AnswerRe: New Release PinmemberPavlo Domanskyy17-Dec-12 4:05 
QuestionNot working for me Pinmemberiplocker5-Sep-12 6:58 
AnswerRe: Not working for me PinmemberMember 96532953-Dec-12 11:08 
GeneralRe: Not working for me Pinmemberlkgamage3-Dec-12 17:43 
GeneralRe: Not working for me Pinmemberderstudent13-Dec-12 8:33 
GeneralRe: Not working for me Pinmemberlkgamage13-Dec-12 8:42 
Questiondecent work Pinmembergabegabe19-Jul-12 14:44 
AnswerRe: decent work Pinmembershazzy8730-Jul-12 4:47 
AnswerRe: decent work Pinmemberjarl_us14-Aug-12 2:59 
QuestionContact name not displaying PinmemberMember 26817415-Jun-12 12:06 
AnswerRe: Contact name not displaying PinmemberMember 913963718-Jun-12 21:16 
GeneralRe: Contact name not displaying PinmemberBrianHooch27-Jun-12 8:53 
GeneralRe: Contact name not displaying PinmemberMember 96532953-Dec-12 11:12 
QuestionWindows XP PinmemberMember 904366229-May-12 0:03 
QuestionDitto to the program icon not showing PinmemberMember 903313926-May-12 6:03 
AnswerRe: Ditto to the program icon not showing PinmemberMember 96532953-Dec-12 11:11 
QuestionWorked !! Pinmemberalps198124-May-12 22:48 
QuestionProgram Icon Not Appearing PinmemberDigit-Aria11-May-12 13:19 
Questionworks as advertised PinmemberW J23-Apr-12 21:13 
QuestionHello is this working for 5.5 skype? Pinmemberiplocker26-Nov-11 2:04 
GeneralMy vote of 4 PinmemberVUnreal17-Nov-11 9:48 
QuestionSkype message cleaner not working Pinmembertutingjhayr7-Sep-11 21:29 
AnswerRe: Skype message cleaner not working Pinmemberlkgamage8-Sep-11 5:01 
Questionfile does not download Pinmemberamangrewal7-Sep-11 0:24 
AnswerRe: file does not download Pinmemberlkgamage8-Sep-11 4:55 

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.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 18 Feb 2013
Article Copyright 2010 by lkgamage
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid