Open sitecore interactive media library with asp.net click

I am trying to find out if it is possible to programmatically open the Sitecore library browser from ASP.NET code code by clicking on the server button. While browsing the net, I found an example explaining how to open the media library browser using the Sitecore thumbnail. I tried this approach on a button on the server side of ASP.NET, but it did not work with object reference not set to an instance of an object .

Can anyone help me if you know how to open the Sitecore media browser in a modal dialog using a button on the server side?

My code is:

 protected void btnShowMediaPopup_Click(object sender, EventArgs e) { Database masterDb = Factory.GetDatabase("master"); UrlString url = new UrlString(UIUtil.GetUri("control:Sitecore.Shell.Applications.Media.MediaBrowser")); Item folderItem = masterDb.GetItem("/sitecore/media library/Images"); url["ro"] = folderItem.Uri.ToString(); SheerResponse.ShowModalDialog(url.ToString(), true); } 
+4
source share
1 answer

I have found a solution. Steps:

a. Created the configuration file "MediaBrowser.config" and added to the App_Config / Include folder (xml setting below):

 <configuration xmlns:patch= "http://www.sitecore.net/xmlconfig/"> <sitecore> <commands> <command name="example:MediaBrowser" type="SitecoreTraining.HelperClasses.MediaBrowser,SitecoreTraining" /> </commands> </sitecore> </configuration> 

b. In my ascx check markup for opening a media browser, the following has been added:

 <A class="scChromeCommand" title="Open Media Browser" onclick="javascript:Sitecore.PageModes.ChromeManager.postRequest('example:MediaBrowser(id=<%# Sitecore.Context.Item.ID.ToString() %>)',null,false)" href="#"><IMG alt="Open Media Browser" src="http://localhost:2438/temp/IconCache/applications/16x16/photo_scenery.png" width="16" height="16" /></A> 

from. Created a MediaBrowser class that inherits the sitecore command line class with the following basic methods:

public override void Execute (CommandContext context) {

  Item item = context.Items.Length == 0 ? Context.Item : context.Items[0]; contextItem = item; var parameters = new NameValueCollection(); wizardPipeline = Context.ClientPage.Start(this, "Run", parameters); } 

protected virtual void Run (ClientPipelineArgs args) {

  Database masterDb = Factory .GetDatabase("master"); if (args.IsPostBack) { var itemID = args.Result; } else { UrlString url = new UrlString (UIUtil .GetUri("control:Sitecore.Shell.Applications.Media.MediaBrowser" )); Item folderItem = masterDb.GetItem("/sitecore/media library/Images" ); url["ro" ] = folderItem.Uri.ToString(); SheerResponse.ShowModalDialog(url.ToString(), true ); args.WaitForPostBack(true ); } } 
+1
source

Source: https://habr.com/ru/post/1394931/


All Articles