It turns out that this is happening because of a cache. Windows Explorer caches files (especially small, “system” files like shortcuts which include bookmarks). The problem is that it can cache them prematurely, so if the file is invalid (e.g., during development) or it gets cached before the file has finished being written (‽), then Explorer will continue to use that until the cache is cleared. Obviously one way to fix it is to simply clear the cache, but the only obvious way of doing that is to reboot (maybe also log out and back in). Of course this is not ideal, especially if you are still in the middle of development.
A knowledge-base article says it applies to Windows XP, Vista, and Server 2003 with Internet Explorer 7 and has a hotfix for them, but it happens with Windows 7 with IE9 as well, which has no hotfix (even though the hotfix was issued in October 2011, long after Windows 7 was released).
An easy way to work around this is to rename either the bookmark file, or the containing folder. Either way, Explorer sees it as a “new” file and ignores the cache.
A common concern is that you cannot simply rename the file or folder every time that you run the program (well you can, but it’s not ideal). Therefore you will want to resolve the issues that cause Windows to cache the bad files. Here’s a few tips on doing this:
Reduce the amount of time between the creation of the empty .url
and writing its contents. For example, instead of opening/creating the file, then building the contents as strings and writing them to the file, consider building the contents (which are simple and small anyway) as a string before opening the file. Then dump the contents and close it. This makes it more likely that by the time that Windows notices the file, it will already have its contents.
Check that the file encoding is not Unicode, BOM, etc. Now that Unicode characters are acceptable in URLs, a .url
file will not be ASCII-only, it might have some UTF-8 characters, but the whole thing won’t be wide-chars.
Check that your line-endings are CR+LF
. When writing to the file, it is easy to simply append a \n
, but you should use \r\n
like Windows and browsers do.
Make sure that the file does not contain illegal characters. It shouldn’t normally be possible, but it can happen.
In addition, some bookmarks will naturally have the generic globe icon and throw an error when you try to open them. This is true for any bookmarks that link to different protocols which are not set up in the system to be opened via bookmarks:
- Chrome internals pages like
chrome://version
- Bookmarklets like
javascript:alert('Woot!');
- P2P protocols like
ed2k://…
if the protocol is not registered with the system