Click here to Skip to main content
15,881,803 members
Articles / Web Development / XHTML

Internet Explorer Favorites, deconstructed

Rate me:
Please Sign up or sign in to vote.
4.83/5 (19 votes)
24 Dec 2007CPOL6 min read 140.4K   746   62  
Description of the binary format used to store internet explorer favorites, includes Favorites-to-XBEL example project.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace CodeProject.IEFavDecon
{
    /// <summary>
    /// Interop wrapper for the legacy "PrivateProfileString" API.
    /// </summary>
    public class IniFile
    {
        [DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileStringA", CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int WritePrivateProfileString(string section, string key, string value, string filename);

        [DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileStringA", CharSet = CharSet.Ansi, SetLastError=true)]
        private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder returnString, int returnSize, string filename);

        private string filename;

        public IniFile(string filename)
        {
            this.filename = filename;
        }

        public string GetValue(string section,string key,string defaultValue)
        {
			StringBuilder sb = new StringBuilder(32768);
            GetPrivateProfileString(section, key, defaultValue, sb, sb.Capacity, filename);
			return sb.ToString();
        }

        public void WriteValue(string section, string key, string value)
        {
            if (WritePrivateProfileString(section, key, value, filename) == 0)
            {
                throw new Exception("WritePrivateProfileString failed: code " + Marshal.GetLastWin32Error().ToString());
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Architect
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions