IShellUIHelper::AddFavorite Method

Prompts the user with a dialog box to add the specified URL to the Favorites list.

Syntax

HRESULT AddFavorite(
    BSTR URL,
    VARIANT *Title
);

Parameters

  • URL
    [in] A BSTR that specifies the URL of the favorite to add to the Favorites list.
  • Title
    [in] A pointer to a VARIANT of type VT_BSTR that specifies the suggested title to use in the Favorites list. The user can change the title in the Add Favorite dialog box. If Title is not specified, URL is used as the title of the favorite.

Return Value

Returns S_OK if successful, or an error value otherwise.

Remarks

Calling the IShellUIHelper::AddFavorite method prompts the user with the same dialog box that is displayed when the user selects Add to Favorites from the Favorites menu.

The URL parameter must specify a valid URL using HTTP, Secure Hypertext Transfer Protocol (HTTPS), or File Transfer Protocol (FTP) protocols only. Calling the IShellUIHelper::AddFavorite method with a file:// or javascript: URL returns E_ACCESSDENIED .

Because the Title parameter is used as a file name when storing the favorite, it cannot contain characters that have been reserved by the file system. If present, the following characters are removed from Title before the Add a Favorite dialog box appears.

  • backslash (\)
  • apostrophe (*)
  • question mark (?)
  • double quotation mark (")
  • less than sign (<)
  • greater than sign (>)
  • pipe (|)

Additionally, slash marks (/) in Title are converted to hyphens (-), and leading and trailing spaces are trimmed. If no suitable characters are found in Title, the URL of the favorite is used instead.

If the favorites are stored on a drive that does not support long file names, only one dot (.) is allowed. Additionally, the title is trimmed to 8.3 and spaces are converted to hyphens.

This method is not supported in HTML Applications (HTAs).

Windows Internet Explorer 8 and later. For security reasons, the IShellUIHelper::AddFavorite method must be called as a response to a user-initiated action, such a mouse click. If called from a different context, such as the onload event of the body element, the IShellUIHelper::AddFavorite method fails silently.

See Also

IDM_ADDFAVORITES, How to Add a Shortcut Icon to a Web Page