My blog has moved to http://www.ascentium.com/blog/sp/default.aspx

For SPDeploy information visit http://www.ascentium.com/blog/sp/Post29.aspx

Wednesday, June 27, 2007

How To: Use SharePoint Explorer View in an ASP.NET page

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

 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" width="600" height="400" name="frmFolder" 
    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.

1 comments:

Anonymous said...

Thas looks very intersting, but can you please give an example that non-programmers can use, for example in a content editor web part or in an example page..
I cant make it work
Thanks
Orfeo