Update: Although the soution here is not strictly supported as I modified core.js to quickly demonstrate the functionality, the note at the end of the post shows how to make it a supported change. Just thought I would mention this as some people have been commenting about unsupported changes....
The standard send to other location functionality in MOSS leaves bit to be desired as the end user is forced to paste a URL into the textbox of a target lit to send the document to.
This post shows how we can place an asset picker in the page to assist the end user in selecting a target location. This is the send to functionality I am referring to:-
First of all the send to another location link takes you to a layouts page called copy.aspx. We will make a copy of this page so as not to alter the original and call it copy2.aspx in the same folder (C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS).
The picker we are going to use is on re-purposed from the site manager page. I'll briefly describe how the picker is launched. There is a function called LaunchPickerTreeDialog contained inside the PickerTreeDialog.js, this in turn calls a general modal dialog box function inside core.js. As long as we pass the appropriate parameters to this call we can re-use the tree picker.
First we need to add a reference to the PickerTreeDialog.js file, I added my script reference under the page head content placeholder like so:-
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
<script type="text/javascript" language="javascript" src="/_layouts/1033/PickerTreeDialog.js"></script>
Secondly we need to add a button and attch the script to it to launch the picker, find the following piece of code:-
<TD class="ms-authoringcontrols" width="100%" colspan="2
<wssawc:InputFormTextBox Title="<%$Resources:wss,copy_enterfolder%>" class="ms-input" ID="TxtFolder" Columns="35" Runat="server" maxlength=255 size=60 width=100% />
and replace it with this:-
<TD class="ms-authoringcontrols" width="100%" colspan="1">
<wssawc:InputFormTextBox Title="<%$Resources:wss,copy_enterfolder%>" class="ms-input" ID="TxtFolder" Columns="35" Runat="server" maxlength=255 size=60 width=100% />
</td>
<td colspan="1">
<script>
function launchPicker()
{
var url=location.protocol + "//" + location.hostname ;
var callback=function(arr)
{
if(arr==null || arr==undefined)
return;
var site=arr[1];
var list=arr[2];
var x=document.getElementById("sendToBrowse").parentNode.previousSibling.children[0]; <!-- this will need to change if you change the layout -->
x.value = url + site + (site == '/' ? '' : '/') + list;
}
LaunchPickerTreeDialog("Select Destination","","","",url,null,"","","/_layouts/images/Copy.gif", 0, callback );
}
</script>
<input type="button" id="sendToBrowse" onclick="launchPicker();" value="...">
</TD>
Now all we need to do is make the send to functionality call our new copy.aspx page instead of the original copy. Locate core.js in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033. If you search inside that file for copy.aspx, there are two places it is defined, edit both to say copy2.aspx. That's it! The send to other location functionality will now use our modified screen, complete with location picker dialog.
The end result should look like this:-
The method I have detailed here does involve making a change to core.js which is not strictly speaking a supported modification, also it will affect all sites on the machine.
With a little extra work you can get around this. Instead of modifying the core.js file directly you can just take a copy of the function in which those changes reside (AddSendSubMenu) and override it in your own custom javascript file. This can be achieved with either a custom site definition specifying a CustomJSUrl property (see SDK for more details) or by creating a copy of the default master page, making the sites inherit from that and embed a reference to your custom JS file in there.
Wednesday, 29 August 2007
How to add a picker to the send to other location screen
Subscribe to:
Post Comments (Atom)
17 comments:
Great stuff
Hi,
I'm using SharePoint services 3 and there doesn't seem to be PickerTreeDialog.js. Because of that LaunchPickerTreeDialog(...) is not working (IE7 reports error on this statement and ignores mouse down event on sendToBrowse button. Or am I missing something? What SharePoint product are You working on?
Yes unfortunnately this does only work on MOSS as the site manager which uses the tree picker dialog is not available on WSS only.
I'm getting
"Faulting application w3wp.exe, version 6.0.3790.1830, stamp 42435be1, faulting module unknown, version 0.0.0.0, stamp 00000000, debug? 0, fault address 0x00690062." error whenever using edited (or only saved) the copy2.aspx.
Seems like SharePoint is checking whether file was modified and does not allow to use it in such a case.
Any ideas on how to fix it?
Can you email me your copy2.aspx and modified javascript file and I'll take a look?
blog@planetwilson.co.uk
ohh.... I just tried editing the file using Notepad. IT IS working.
Seems like SharePoint Designer is altering the file when I'm saving it for the first tiem (without doing any changes at all) and this is destroying it in some way.
BTW- it's also working for cross-web application quesries! Marvellous!
Can you pick multiple destination sites?
Otherwise, its still a cool feature.
No as the underlying functionality only accepts a single target location, all this does it prepopulate the box for you.
Do I need to restart Sharepoint or anything to get this to work?
I've made the changes and saved copy2.aspx, and overridden the AddSendSubMenu() javascript function in my master page. However, in IE I still get the old (copy.aspx) page. In Firefox, or if I change the URL by hand in IE, I get the "Unknown error" page from Sharepoint.
Now, because there's a difference in behavior in IE and Firefox, it seems like there might be a problem with the javascript. But even putting in the URL with copy2.aspx and the appropriate arguments, I get this error message, so there's something more fundamentally wrong going on. Any ideas?
This mihgt be down to the overridden function, can you send me a copy of what you have in your page currently? Where is the overriden function?
blog@planetwilson.co.uk
Hi, Mark
I tried it and it works perfect, except ......
It does not return anything to the textbox.
Do you have any ideas on how to fix it?
Can you email the source of the page and I will take a look?
Ok, this has some serious things with it...
First, it doesn't return sub directory folders, only root folder.
Second, it only works if all your sites are sub sites of a main collection. If you have multiple site collections you won't be able to access them respective of this control.
I have a version I am working on that tries to correct some of this but has anyone else encountered these issues?
First of all I am sorry if it doesn't quite fit your needs. The solution re-uses one of the publishing features of the picker hence being restricted to the current site collection. That is just how the publishing picker works. I'll see if I can find time to look into making it work with folders.
If you create a better solution I would be happy to link to it.
Well here is what I found. Hoping to build on your solution I was excited to see your progress. After some digging it looks like I may have to custom build this.
It seems that the PickerTreeDialog.js gets its return values for the link you click on from the PickerTreeView.aspx. This page has a variable called:
var strDlgReturnValue
This is an array (3 elements) that stores the following information:
= smtPickerSelection.Value
= smtPickerSelectionWebServerRelativeUrl.Value
= smtPickerSelectionListName.Value
Now after playing with this I have found that ListName will only return the list name from the top level as does WebServerRelativeUrl. So it seems that the picker does not actually go to the Item level. I am trying to see if I can get it to go that deep but am thinking it may be easier to just rewrite my own.
great solution....wondering why I am getting a 404 not found when I click the ... link on the copy2.aspx page.
denzil (dnotorious@rogers.com)
var url=location.protocol + "//" + location.hostname + ":" + location.port;
I had to modify the above line to include the port since I wasnt on 80
dnotorious@rogers.com
Denzil
Post a Comment