Blogging

Sharepoint 2010 LaunchPickerTreeDialog , Folder picker

Sending
User Rating 5 (1 vote)

There have been many instances when one required to upload the document to the document library in a particular folder. If one have noticed that while  uploading the document to document library we get a browse option which let one to select the folder to  add the document in library.

To achieve this sharepoint uses the LaunchPickerTreeDialog method this can be found in /_layouts/1033/PickerTreeDialog.js file under 14 hive folder.  This is used to display the site content and filter the content based on the WebOnly, listOnly, WebAndLIsts and websAndListFolders.

Now the if you want to reuse the same in your custom control, and want to list only particular document library folder for example to list folders in pages library in launch picker, the hack here is about how to pass on the filter parameter to LaunchPickerTreeDialog method .

Creating the anchor tag format is “SPList:[ID]?SPWeb:[ID]”
Example:

<br />
	var pagesList = &lsquo;SPList:&lt;%= SPContext.Current.Web.GetList(&ldquo;/Pages&rdquo;).ID %&gt;?&rsquo;;<br />
	var webID = &lsquo;SPWeb:&lt;%= SPContext.Current.Web.ID %&gt;:&rsquo;;<br />
	LaunchPickerTreeDialog(&#39;CbqPickerSelectListTitle&#39;, &#39;CbqPickerSelectListText&#39;,&nbsp; &#39;listsOnly&#39;, pagesList+webID, &#39;&lt;%= SPContext.Current.Web.ServerRelativeUrl %&gt;&#39;, &#39;&#39;, &#39;&#39;, &#39;Error Occured&#39;,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;/_layouts/images/smt_icon.gif&quot;, &#39;&#39;, callback, true, &#39;&#39;);<br />
	

Complete code

<br />
	&lt;SharePoint:InputFormTextBox Title=&quot;Select file or folder&quot; class=&quot;ms-input&quot; ID=&quot;URLTextBox&quot; onfocusout=&quot;javascript:CheckSubFolderSelected();&quot;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Columns=&quot;35&quot; runat=&quot;server&quot; MaxLength=&quot;455&quot; size=&quot;60&quot; /&gt;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;asp:Button ID=&quot;BrowseToButton&quot; runat=&quot;server&quot; OnClientClick=&quot;launchPicker();return false;&quot;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text=&quot;...&quot; /&gt;<br />
	

 
JavaScript

<br />
	&nbsp; function ULSfGQ(){var o=new Object;o.ULSTeamName=&quot;DLC Server&quot;;o.ULSFileName=&quot;UploadEx.aspx&quot;;return o;}<br />
	&nbsp;&nbsp;&nbsp;&nbsp; var rptstglocid = &lt;%SPHttpUtility.AddQuote(SPHttpUtility.NoEncode(URLTextBox.ClientID),Response.Output);%&gt;;<br />
	&nbsp;&nbsp;&nbsp; var weburl=&lt;%SPHttpUtility.AddQuote(SPHttpUtility.UrlPathEncode(Web.Url,true),Response.Output);%&gt;;<br />
	&nbsp;<br />
	&nbsp;function launchPicker()<br />
	&nbsp;{ULSxQp:;<br />
	&nbsp;&nbsp;&nbsp; var callback = function(dest)<br />
	&nbsp;&nbsp;&nbsp; {ULSxQp:;<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (dest != null &amp;&amp; dest != undefined &amp;&amp; dest[3] != null)<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // alert(dest[0] +&#39;-&#39;+dest[1]+&#39;-&#39;+dest[2]);<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById(rptstglocid).value = dest[3];<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
	&nbsp;&nbsp;&nbsp; };<br />
	&nbsp;<br />
	&nbsp;&nbsp;&nbsp;&nbsp; var pagesList = &#39;SPList:&lt;%SPHttpUtility.NoEncode(ListID,Response.Output);%&gt;?&#39;; // get the list id based on the library name<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var webID = &#39;SPWeb:&lt;%= SPContext.Current.Web.ID %&gt;:&#39;;<br />
	&nbsp;&nbsp;&nbsp; //alert(pagesList+webID);&nbsp; // create the anchor tag<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LaunchPickerTreeDialog(&#39;CbqPickerSelectListTitle&#39;, &#39;CbqPickerSelectListText&#39;,<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;listsOnly&#39;, pagesList+webID, &#39;&lt;%= SPContext.Current.Web.ServerRelativeUrl %&gt;&#39;, &#39;&#39;, &#39;&#39;, &#39;Error Occured&#39;,<br />
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;/_layouts/images/smt_icon.gif&quot;, &#39;&#39;, callback, true, &#39;&#39;);<br />
	&nbsp;}<br />
	&nbsp;

 Thanks.

Share your Thoughts