API
Version 7.x > API > setting value of MediaSelectionControl using api View modes: 
User avatar
Member
Member
ap - 12/21/2012 1:11:54 PM
   
setting value of MediaSelectionControl using api
hello.
I'm interested in setting the value of MediaSelectionControl using api.
The media selection control has been assigned to a document type form field with this control.
i've tried using node.setvalue("MediaFileColumn","~/SITE/FILE.mp3") but this doesn't work. (also did node.Update() after setValue)

Any ideas?

Thank you.
AP

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 12/21/2012 9:07:44 PM
   
RE:setting value of MediaSelectionControl using api
Hello,

Regrettably, I am not sure what do you mean by MediaSelectionControl. Could you please let me know the exact file name of the control you are referring to or any other pointers so I know, which control do you mean?

Best regards,
Boris Pocatko

User avatar
Member
Member
ap - 12/24/2012 9:35:55 AM
   
RE:setting value of MediaSelectionControl using api
Hello.
Site Manager -> document types -> Fields -> under field appearance the form control is "Media Selection".

Thanks for the help.
AP

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 12/24/2012 11:03:19 AM
   
RE:setting value of MediaSelectionControl using api
Hi,

I am using this code:

// Create an instance of the Tree provider first
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

// get the node for testing purposue directly by it's node ID
TreeNode node = tree.SelectSingleNode(1163);

if (node != null)
{
// Change coupled data
node.SetValue("NewsTitle", "Title changed from code");

node.SetValue("MediaSelectorColumn", "~/CorporateSite/media/Gallery/document.pdf&ext=.pdf");

// Save to database
node.Update();

}


And it is working just fine and given value is saved and the file is accessible.

Best regards,
Juraj Ondrus