System.Shell.knownFolder/knownFolderPath - do they work?

Using either knownFolder or knownFolderPath in the following code just produces the error "automation server can't create object".

Has anyone managed to use either of these functions successfully

<html>
<head>
<script language="javascript">
try{
var p = System.Shell.knownFolderPath("My Documents");
} catch(err) {System.Debug.outputString(err.name+" - "+err.message)}
</script>
</head>
<body style="width:100px; height:100px; margin:0px;"></body>
</html>


Answer this question

System.Shell.knownFolder/knownFolderPath - do they work?

  • SonAsylum

    I never got an answer to this one, although I'm certain the documentation is incorrect.

    knownFolder specifies "Takes a string that represents a user's well-known folder, such as My Documents, and returns an instance of a System.Shell.Folder object based on that folder path." and yet the parameters are listed as:

    "oKnownFolderPath Required. An instance of a System.Shell.Folder object based on the specified well-known folder."

    Which makes me believe it needs a System.Shell.Folder object and not a string as a parameter.

    knownFolderPath's parameter is listed as:

    "oKnownFolder Required. The well-known name of the folder as a string."

    So, what is the parameter A string or a System.Shell.Folder object Perhaps someone from MS can get the documentation corrected and provide a working example.

  • Jamie Thomson

    Could be a bug. RecycleBinFolder always generates an error. It's a valid value though.

    Perhaps MS can verify this for us.

  • QWERTYtech

    The doc parameter looks wrong, it should be a string name, but the known folder variable you're using of "My Docuements" is the real source of the (very unfortunate) "Automation server..." error.

    I can't find the list of Known Folders for Vista right now, but the one you're looking for is "documents". That will return a path in my quick test.

    System.Shell.knownFolderPath("documents");

    Brian


  • AlanKohl

    Thanks for the full list Bruce.

    You just need to get it put up on MSDN now, as those docs are completely misleading!

  • Canada Goose

    Hi,

    I've been trying to use (in javascript within a gadget) System.Shell.knownFolder, System.Shell.knownFolderPath, and System.Shell.itemFromPath to get a hold of the value of "RecycleBinPath". I've noticed that this always causes a javascript exception, with the lovely message "Object error". Now, if I used a bad path, like "RecyclceBinFolder", I get the automaton error I expect due to a malformed path, so that's not what's going on.

    I can use all of the above methods to get OTHER folders, but I cannot get a reference to the RecyleBin in this way. Additionally, I even tried hardcoding the path "C:\$Recycle.Bin" into a itemFromPath and, ta-da, same object error!

    This *implies* to me (read: probably wrong) that the javascript language bindings for recycle bin objects are somehow broken, and simply explode whenever they would otherwise succeed. I mean, I can't even get the string path back with this, but I can use it for known folders like "documents" (which works fine). Am I missing something Any thoughts

  • Bernaridho

    You could try browsing to the desktop and then from there to the recycle bin - I'm pretty sure "Recycle Bin" is a folder on desktop.

  • god_of_coolness

    "C:\$Recycle.bin" is an empty folder for me, even though I have quite a few items in my recycle bin. Maybe System.Shell.knownFolder("RecycleBinFolder") returns "C:\$Recycle.bin", which is empty

    Andy

  • AliciaV

    Andy,

    Thank you for the suggestions. Unfortunately, I don't know what knownFolder returns - it explodes during the call itself, it never makes it as far as actually returning. It wouldn't shock me.

    As far as browsing for it on the desktop, I think that this would probably just get to the same problem via a different route. Plus, not everyone has the Recycle Bin on their desktop: it is optional (I have mine turned off, for example). A good idea and thank you for the response, but I'm afraid its not viable.

    My guess is that the Recycle Bin is a "magic" folder. As in, you can't get its contents, you can't navigate through it, and you can't directly touch anything inside it (thus the existence of System.Shell.RecycleBin); unfortunately, this makes it nigh-impossible to do some things correctly (for example: figure out how much space is actually free on a drive. The "used space" includes the recycle bin; but you can't get a tally of just one drive's recycle bin contents, so you can't tell how much of the drive is REALLY free unless you go count up the size of every single file - not a pleasant prospect).

  • Greg Christensen

    Sorry for the bad docs. Here's the list of strings that the knownFolder/knownFolderPath APIs will accept:

    Desktop
    Startup
    StartMenu
    Documents
    Programs
    CommonStartup
    CommonPrograms
    PublicDesktop
    PublicFavorites
    PublicDocuments
    System
    SystemX86
    Profile
    Windows
    Pictures
    Music
    Videos
    ProgramFiles
    ProgramFilesCommon
    ProgramFilesX86
    ProgramFilesCommonX86
    AdminTools
    CommonAdminTools
    PublicMusic
    PublicPictures
    PublicVideos
    UserProfiles
    Downloads
    PublicDownloads
    GadgetsUser
    RecycleBinFolder


  • Harrynet

    Also - while I'm on the topic (apologies for the double-post), how does the System.Shell.RecycleBin interact with multiple drives In XP (not sure about Vista), each drive could have its own RecycleBin; so would the values reported by System.Shell.RecycleBin be cumulative across all drives, or is there a way to discriminate between, say, Drive C's recycle bin and Drive D's recycle bin

  • Vladimir Bougay

    Why not use Explorer eg.

    System.Shell.execute("explorer.exe", "desktop");
    System.Shell.execute("explorer.exe", "documents");
    System.Shell.execute("explorer.exe", "pictures");
    System.Shell.execute("explorer.exe", "c:\my folder");



  • Johnny Raved

    Okay, I have a question that might be related to this topic...

    I am using the code below in a gadget that simply links to My Docs. The problem I am facing is that I have only been able to link the gadget to My Docs, Network Connections, and Recycle Bin. Those are the only folders I could find the string paths too... Is there an alternative to using var Path= "::{string}"; I would imagine System.Shell.knownFolder would work if I knew where to put it in the code. (I am a newb to gadgets) I would really like to link to My Music, My Pictures, My Videos, E:\Downloads or any folder I want. I hope someone understands what I am trying to do here, and hope someone can help me out a little. If this isnt the right place to ask this question, I apologize sincerely!

    <html>
    <head>
    <title>MyDocs</title>
    </head>
    <style type="text/css">
    body
    {
    background-image: url(icon.png);
    background-repeat: no-repeat;
    width: 127px;
    height: 67px;
    }

    #main
    {
    z-index: 20;
    width: 127px;
    height: 67px;
    }
    </style>
    <body scroll='no'>
    <div id="main" ondblclick="launchMydocs();"></div>
    </body>
    <script type="text/javascript">
    function launchMydocs()
    {
    var Path = "::{450D8FBA-AD25-11D0-98A8-0800361B1103}";
    System.Shell.execute(Path);
    }
    </script>
    </html>



  • System.Shell.knownFolder/knownFolderPath - do they work?