For any SharePoint document library there is a default view called "Explorer View". This view displays the the contents of the document library as Windows explorer window that can be used to drag/drop or copy/paste files. This is very handy when transferring large sets of files/folders to a SharePoint document library.

image_thumb

Recently I implemented this view in a custom aspx page. Here's how I did it:

  1. Add the explorer view container to your page. The explorer view uses an iframe as the container for the windows explorer window. Here is what the markup should look like.
    <iframe id="frmFolder" 
        name="frmFolder" 
        width="600" height="400" 
        src="/_layouts/blank.htm" class="ms-httpFolder">
    </iframe>
  2. Initialized the explorer view container. Add the following code to your OnLoad page handler to initialize the iframe. In this example I am loading the root folder of the site collection. You can load any SharePoint folder you like.
    string js = string.Format(@"
            function navtoframe() {{ NavigateHttpFolderIfSupported('{0}{1}', 'frmFolder'); }} 
            _spBodyOnLoadFunctionNames.push('navtoframe');"
        , SPContext.Current.Site.Url
        , SPContext.Current.Site.RootWeb.RootFolder.ServerRelativeUrl);
    
    Page.ClientScript.RegisterStartupScript(GetType(), "frmFolder", js, true);

The NavigateHttpFolderIfSupported method is defined in the core.js file, which is a part of the SharePoint infrastructure and is associated with all SharePoint pages.

Here is something that has proven invaluable to me when trying to get a leg up as a consultant with the SharePoint platform. Use .NET Reflector to deduce how the SharePoint API is implemented.

For the uninitiated, .NET Reflector is a free (and most excellent) tool written by Lutz Roeder that uses the reflection features built into the .NET framework to allow you to browse and even decompile any assembly. Yes! It's true you can open any assembly in reflector and see the source code. With only minimal trade-offs this allows you to see the author's implementation. In terms of SharePoint this means that you have a ton of examples at your fingertips. All you have to do is open the SharePoint assemblies and/or executables in Reflector to see how they are implemented.

There is one situation where this approach isn't viable. Assemblies can be "obfuscated" which means that all private methods/properties/fields are scrambled such that they are not readable by humans. In general this is a tactic used by commercial software companies to protect trade secrets. Thankfully (and I mean thank god!) the SharePoint team decided not to obfuscate their assemblies. There are minor exceptions, some security related code is obfuscated, but 99.9% of all SharePoint assemblies and executables can be decompiled.

Let's face it, the SharePoint documentation is not that great. Yes, there are some decent examples, but there are also lots of things like "SPWeb.Update() : Updates the web." This is not going to be helpful for people like us who are spelunking into the bowels of the SharePoint beast.

Here's an example. I recently had the need to update the farm credentials via the API (don't ask why, just go with me here.) Guess what, stsadm does this function from the command line and stsadm.exe can be decompiled.

Open up Reflector. Drag in stsadm.exe, then navigate to the SPUpdateFarmCredentials operation. Bingo, here's how you update the farm credentials.

image_thumb

top