Click here to Skip to main content
Licence CPOL
First Posted 6 Apr 2010
Views 5,265
Downloads 93
Bookmarked 9 times

Export Web Browser's Favorites To XML File

By | 6 Apr 2010 | Article
The aritcle gives you a way to export web browser's favorites.
demo src

Introduction

The article will show you an easy method to export web browser's favorites. As we all know, the function import and export favorites of web browser has been deleted. So we must do this by ourselves.

About the Code

If you want to export the favorites, you must know where they are. They can be found in the *.URL's directory by register. After that, read all the items and get names and URLs. The problem is how to get the URL of *.url files? Actually, it's very easy. "*.url" files are the same as "*.ini" files. So you could manipulate it like you manipulate INI files. Look at the following context:

[DEFAULT]
BASEURL=http://faq.csdn.net/read/196943.html
[InternetShortcut]
URL=http://faq.csdn.net/read/196943.html Modified=D09A951BEAD2CA01A1

Open the *.url files, you will find the snippets.

void CExportDlg::OnExport() 
{
	// TODO: Add your control notification handler code here

	CString strFilePath,favpath;

	// Get the location of favorites.
	HKEY hKEY;
	DWORD type=REG_SZ;
	LPCTSTR path=
	    "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
	DWORD cbData=80;
	TCHAR buf[512];

	::RegOpenKeyEx(HKEY_CURRENT_USER,path,0,KEY_READ,&hKEY);
	::RegQueryValueEx(hKEY,"Favorites",NULL,&type,(LPBYTE)buf,&cbData);
	::RegCloseKey(hKEY);
	favpath.Format ("%s",buf);
	favpath+="\\*.url";

	GetDlgItem(IDC_EDIT1)->GetWindowText (strFilePath.GetBuffer (256),256);

	BOOL bWorking;
	CFileFind ffd;
	bWorking=ffd.FindFile (favpath);
	CString strUrl;

	if(strFilePath!="")
	{
		CMarkup xml;

		xml.AddElem ("main");
		xml.AddAttrib ("version","2"); 
	         LPSTR url=new char[512];

		while(bWorking)
		{
			bWorking=ffd.FindNextFile ();
			if(!ffd.IsDots()&&!ffd.IsDirectory ())
			{
				GetPrivateProfileString("InternetShortcut",
					"URL",NULL,url,512,ffd.GetFilePath ());

				xml.AddChildElem ("ITEM",url);
				xml.IntoElem(); 

			    xml.AddAttrib ("IsFolder","0");

				CString AttribName;
				AttribName=ffd.GetFileName();
				xml.AddAttrib ("name",AttribName.Left 
					(AttribName.GetLength ()-4));
				xml.OutOfElem ();
			}
		}
		delete [] url;

		CString csXML=xml.GetDoc ();
		CString xmlfile;
		xmlfile=" ";
		xmlfile+=csXML;	
		CFile file(strFilePath,CFile::modeWrite|CFile::modeCreate );
		file.WriteHuge (xmlfile.GetBuffer (5000),xmlfile.GetLength ());
		if(IDOK==AfxMessageBox("Export finished!"))
			this->PostMessage (WM_CLOSE,0,0);
	}
}

CMarkup is a class I found on CodeProject... I would really like to thank the author. Hope it will be useful for you.

History

  • 7th March, 2010: Initial post

License

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

About the Author

Aric Green

Engineer
Huawei Tech. Ltd.
China China

Member

Although I was a college studnet now as the same I was also a teacher of C/C++/3DS MAX/website for National Computer Rank Examination.I began to study computer when I was a child 8 year's old.I use BASIC/C/C++/VB/VF/VC/DELPHI/.NET to programming.When in college I was the chairman of Computer Association of our school and I take part in ACM Competition twice in two years.I also was the only person who take part in the National Mathematical Contest in Modeling twice in two years of our school.I like computer programming very much.Hope to be your friend.thx!

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
GeneralMy vote of 1 PinmemberDennisAT8:51 7 Apr '10  
GeneralRe: My vote of 1 PinmemberAric Green15:20 7 Apr '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 7 Apr 2010
Article Copyright 2010 by Aric Green
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid