From C#:
Create a console application in visual studio & copy the following code in main method.
//Code
GetFavoriteFiles(Environment.GetFolderPath(Environment.SpecialFolder.Favorites));
foreach (string s in favFiles)
{
Console.WriteLine(s);
}
Console.Read();
//
in the above code 'GetFavoriteFiles("..")' is method which gets the favorite files in that folder & in sub folders if any. The method looks like this
//Code
static List
private static void GetFavoriteFiles(string folder)
{
string[] favs = Directory.GetFiles(folder);
favFiles.AddRange(favs);
string[] folders = Directory.GetDirectories(folder);
if (folders != null)
{
foreach (string s in folders)
{
GetFavoriteFiles(s);
}
}
}
//
The above code gets all the IE favorites in form of *.url files.
JavaScript Code :
var i=0;
var favString="";
var fso;
function Import()
{
try
{
fso=new ActiveXObject("Scripting.FileSystemObject");
if(fso !=null )
{
//Create windows script shell object to access Favorites folder in user system.
var object=new ActiveXObject("WScript.Shell");
var favfolderName=object.SpecialFolders("Favorites")
if(favString=="")
{
GetFavourites(favfolderName);
}
} .
}
catch(err)
{
alert("Security settings to be modified in your browser ")
}
}
//Recursive method which retrieves Favourite Name & URL for a given folder & subfolders. function GetFavourites(Folder)
{
var FavFolder=fso.GetFolder(Folder);
//Gets Favourite Names & URL's for given folder.
var files=new Enumerator(FavFolder.Files)
for(; !files.atEnd() ;files.moveNext())
{
var fil=files.item();
if(fil.Type=="Internet Shortcut")
{
var textReader=fso.OpenTextFile(fil.Path,1,false,-2)
var favtext=textReader.ReadAll()
var start=favtext.indexOf("URL",16)
var stop=favtext.indexOf("\n",start)
favString+=fil.Name.replace(/.url/,"");
favString+=":URL:";
//to separate favourite name & favorite URL
favString+=favtext.substring(start+4,stop-1);
favString+=":NEXT:"; //to separate favorites.
i++;
}
}
//Checks any subfolder exists
var subfolders=new Enumerator(FavFolder.SubFolders)
for(; !subfolders.atEnd() ;subfolders.moveNext())
{
var folder=subfolders.item();
GetFavourites(folder.Path);
}
}
The above javascript code also extracts the URL of the favorite.