MultipleMediaPickerViaSource

August 15th, 2006

Jonathan kindly asked me how to extend/change the MultiplePagePickerViaSource, he wanted everything the same way, except media files instead of pages listed.

After some mailing with Jonathan, I thought to myself "it should take longer than 3 minutes to do that", and it actually didn't took longer than 3 minutes of coding :-)

Download (All files needed to use MultipleMediaPickerViaSource in umbraco) 12 KB
Download source (Visual Studio 2003 project) 38 KB

If you are succeeded with installing the MultipleMediaPickerViaSource, then please make a comment on this blog post

In short the MultipleMediaPickerViaSource is a Data Type where you can select multiple files of a given media folder, you can also sort the selected files.

See the screenshots to get a better understanding

Setting up data type in umbraco
Screenshot: setting up data type in umbraco

Setting up the document type in umbraco
Screenshot: setting up the document type in umbraco

Selecting files on page
Screenshot: selecting files on page

Xslt inserted via a macro in the editor
Screenshot: Xslt macro inserted in the editor, could be in the template instead

There are many ways of using the MultipleMediaPickerViaSource in umbraco, Jonathan needed a way to select a unlimited number of files to attach a case.

Install
Download (Link is in the top of this post).
Copy the two folders to your site.

How to use
Now you should be able to setup a new Data Type to use CPalm.MultipleMediaPickerViaSource in the Developer section of umbraco.
When you are using the CPalm.MultipleMediaPickerViaSource Data Type in a Document Type is it important to tell the Data Type where to pickup child's (Files).
You are doing this by using the field "Description" on the property, you should write the ID of the mother (Media folder) of the child's you want to get listed.

Example xslt using it

XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library"
	exclude-result-prefixes="msxml umbraco.library">

	<xsl:output method="xml" omit-xml-declaration="yes"/>

	<xsl:param name="currentPage"/>

	<xsl:template match="/">

	<xsl:variable
		name="mediaIdArray"
		select="umbraco.library:Split($currentPage/data [@alias = 'selectedFiles'], ',')" />

	<xsl:for-each select="$mediaIdArray/value">
		<xsl:if test="string-length(.) &gt; 0">
			<xsl:variable name="media" select="umbraco.library:GetMedia(., false())" />
			<a href="{$media/data[@alias = 'umbracoFile']}">
				<xsl:value-of select="$media/@nodeName" />
				(<xsl:value-of select="$media/data[@alias = 'umbracoBytes']" /> bytes)
			</a><br />
		</xsl:if>
	</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Web.Config
You can set some settings in the web.config if you want to - no need to

XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!--
	If your wan't to place the javascript in another location
	(if you use a virtual dir)
-->
<add
	key="MultipleMediaPickerViaSource_JavascriptSrc"
	value="/YouScriptFolder/MultipleMediaPickerViaSource.js"
/>
<!--
	You could skip the IO file check if you wan't
-->
<add
	key="MultipleMediaPickerViaSource_Skip_System.IO.File.Exists_Check"
	value="true"
/>

Final notes
Yes, it only took 3 minutes to make this data type since i could base it on MultiplePagePickerViaSource

5% on actually coding (the funny part)
95% of the time spent on this project was used on documentation, screenshot, preparing code for download, writing blog post etc.

Updated 2006-09-20, I have updated the xslt example with a if statement

 

Tags: Umbraco, Umbraco Extension

Comments

#1 - Michael Chung on August 17, 2006 13:24

I've installed the MultiplePagePickerViaSource successfully - it works great as my 'download file' selector. Slight problem with the case when there is nothing selected though - I get this XSLT error:

System.Xml.Xsl.XsltException: Function 'umbraco.library:GetMedia()' has failed. ---> System.ArgumentException: Cannot widen from target type to primitive type.

I understand this is quite common when using GetMedia, I'm just trying to figure out how to use the xslt:if statement to fix it up.

#2 - Christian Palm on September 20, 2006 13:00

#1 I have updated the xslt example with the IF statement

#3 - Jesper on June 26, 2007 18:16

Hi Christian,

I used this to build a couple of memberPickers ... but I'm wondering about this "addSaveHandler". What is it .. and where is it defined? I'm trying to use the datatypes with autoform .. without any luck .. because of this missing "addSaveHandler" ...

Got a clue?

Kindly,

Jesper

#4 - Ian George on August 14, 2007 15:26

Hi I've used this on a client's site and for the most part it's great. Unfortunately when media that is selected is deleted it leaves blank list items on the selected side that can't be removed. I've hacked the front end of the site to ignore the blank entries for now but is there a more elegant way to handle this?

#5 - Alec on November 20, 2007 20:18

We use this tool however have found a bug.. We have a seit in Korian and the issue is you can add nodes but cannot remove them. Any ideas?

#6 - Rodger on September 16, 2008 15:05

Works fine :)

#7 - Tony on September 29, 2008 16:01

Strange. I've used the MultiContentPicker before and it seems to be working fine. Now when I tried this one the CPalm.MultipleMediaPickerViaSource refuse to show up with other Data Types when I try creating new Data Type.
My CPalm.MultiplePagePickerViaSource showd up after I followed instructions ni installation textfile.

Any suggestions???

Regards, Tony H

#8 - buy viagra on December 06, 2009 23:31

Works fine :)

#9 - Best mp3 Music on December 07, 2009 10:47

Works fine :)
Best regards,

#10 - Dota allstars on December 17, 2009 11:20

rly nice work!

#11 - Buy Viagra Sydney on January 08, 2010 15:04

its work. exelent

#12 - Rent a Car in Ukraine on February 11st, 2010 17:18

Hire a Car in Ukraine

 

Create a new comment

Recent Post

Tags