Find id of chosen mediapicker node Options
Simm
Posted: Thursday, December 20, 2007 5:47:25 PM

Rank: Fanatic

Joined: 7/22/2006
Posts: 255
Location: Randers, Denmark
Hi,

I have a document type with a mediapicker datatype and my own custom Excel-to-SQL converter datatype. In theory, The converter should convert a file selected with the mediapicker, but how do I find the id/name/filename of the chosen node in the Media tree?

Best Regards
Simon

Simm.dk - My base on the web - proud Umbracian since 2.0 Beta
mortenbock
Posted: Thursday, December 20, 2007 6:00:39 PM

Rank: Addict

Joined: 7/19/2006
Posts: 790
Location: Århus, Denmark
Just to understand correctly:

1: You open the page in umbraco
2: You select the media
3: You press a button in your custom datatype?

So you need to get the media @id in you custom datatype? Is that correct?

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

Simm
Posted: Friday, December 21, 2007 3:30:24 PM

Rank: Fanatic

Joined: 7/22/2006
Posts: 255
Location: Randers, Denmark
Hey Morten. Yep, you are correct :)

Best Regards
Simon

Simm.dk - My base on the web - proud Umbracian since 2.0 Beta
mortenbock
Posted: Friday, December 21, 2007 4:37:21 PM

Rank: Addict

Joined: 7/19/2006
Posts: 790
Location: Århus, Denmark
The page that you are on when editing the node is something like: editContent.aspx?id=1071

So first you would get the nodes ID from the querystring like you would on any other webpage.

So to get the ID from the mediapicker you could do this:
Code:

//Get current node ID
int currentnode = int.Parse(System.Web.HttpContext.Current.Request.QueryString("id"));
//Create the node object
umbraco.presentation.nodeFactory.Node n = new umbraco.presentation.nodeFactory.Node(currentnode);
//Get the media ID
int mediaid = n.GetProperty("yourMediaPickerAlias");


This will of course depend on the node being published, so the process would be something like:

1: You open the page in umbraco
2: You select the media
3: Publish the node
4: Press the button in your custom datatype.

Is this the way you wanted to do it?

Morten Bock - Level 2 certified - MVP 2008/2009 - My danish blog with a few english posts

simm2
Posted: Saturday, December 22, 2007 7:04:34 PM
Rank: Enthusiast

Joined: 12/22/2007
Posts: 12
Hi Morten,

Thank you very much, but not quite what I need, I need to find the id of the media item, which I've selected in the mediapicker. Your solution gives me the node id of the page itself, where the mediapicker is located. Thats a start since Node.GetCurrent doesn't seem to work inside Umbraco :D
simm2
Posted: Saturday, December 22, 2007 7:10:03 PM
Rank: Enthusiast

Joined: 12/22/2007
Posts: 12
Errh.. sorry my mistake.. It works perfectly - thanks :)
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.