从asp.net按钮单击打开Sitecore的媒体库编程 [英] Open sitecore media library programmatically from asp.net button click

查看:217
本文介绍了从asp.net按钮单击打开Sitecore的媒体库编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出是否有可能从编程方式打开Sitecore的媒体库浏览器ASP.NET $ C $在服务器端的按钮,单击C-后面。通过搜索网,我发现<一个href=\"http://www.dotnetmafia.com/blogs/kevin/archive/2011/09/13/building-the-thumbnail-button-module.aspx\"相对=nofollow>这解释了如何从Sitecore的缩略图点击打开媒体库的浏览器一个例子。我试图在ASP.NET服务器端按钮点击此方法,但它没有工作与对象引用不设置到对象的实例失败。

任何人都可以请帮助我,如果你知道如何在模态对话框通过服务器端的按钮打开Sitecore的媒体浏览器中点击?

我的code:

 保护无效btnShowMediaPopup_Click(对象发件人,EventArgs的发送)
{
    数据库masterDb = Factory.GetDatabase(主);
    UrlString URL =新UrlString(UIUtil.GetUri(控制:Sitecore.Shell.Applications.Media.MediaBrowser));    项目folderItem = masterDb.GetItem(/ Sitecore的/媒体库/图像);
    网址[RO] = folderItem.Uri.ToString();    SheerResponse.ShowModalDialog(url.ToString(),TRUE);
}


解决方案

我找到了解决办法。步骤如下:

一个。创建配置文件MediaBrowser.config,然后添加到文件夹APP_CONFIG /包括(以下配置XML):


 &lt;结构的xmlns:补丁=htt​​p://www.sitecore.net/xmlconfig/\">
  &LT;&Sitecore的GT;
      &LT;命令&GT;
          &LT;命令名称=例如:MediaBrowser,把TYPE =SitecoreTraining.HelperClasses.MediaBrowser,SitecoreTraining/&GT;
      &LT; /命令&GT;
  &LT; / Sitecore的&GT;
&LT; /结构&gt;


乙。在我的ascx控件标记添加以下打开媒体浏览器:

 &LT; A级=scChromeCommand称号=打开媒体浏览器的onclick =JavaScript的:Sitecore.PageModes.ChromeManager.postRequest('例如:MediaBrowser时(ID =&LT;% #Sitecore.Context.Item.ID.ToString()%GT;),空,假)的href =#&GT;&LT; IMG ALT =打开媒体浏览器SRC =HTTP://本地主机:2438 /temp/IconCache/applications/16x16/photo_scenery.pngWIDTH =16高度=16/&GT;&LT; / A&GT;

℃。创建继承与所用主要有以下方法Sitecore的命令类MediaBrowser的类:


  

公众覆盖无效执行(CommandContext上下文)
  {

 项项= context.Items.Length == 0? Context.Item:context.Items [0];
        contextItem =项目;        VAR参数=新的NameValueCollection();        wizardPipeline = Context.ClientPage.Start(这一点,运行,参数);
    }


  
  

受保护的虚拟无效的run(ClientPipelineArgs参数)
          {

 数据库masterDb =出厂.GetDatabase(主);
        如果(args.IsPostBack)
        {
            VAR ITEMID = args.Result;
        }
        其他
        {
            UrlString URL =新UrlString(UIUtil .GetUri(控制:Sitecore.Shell.Applications.Media.MediaBrowser));            项目folderItem = masterDb.GetItem(/ Sitecore的/媒体库/图像);
            网址[RO] = folderItem.Uri.ToString();
            SheerResponse.ShowModalDialog(url.ToString(),TRUE);
            args.WaitForPostBack(真);
        }
    }


I have been trying to figure out if it is possible to open the Sitecore media library browser programmatically from ASP.NET code-behind on a server-side button click. By searching the net, I found an example which explained how to open a media library browser from a Sitecore thumbnail click. I tried this approach on ASP.NET server-side button click but it did not work failing with object reference not set to an instance of an object.

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

My code:

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);   
}

解决方案

I found a solution. Steps as follows:

a. Created config file "MediaBrowser.config" and added into folder App_Config/Include (configuration xml 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 control markup added the following to open the media browser:

<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>

c. Created a MediaBrowser class that inherits the sitecore Command class with the following main methods used:

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 );     
        }
    }

这篇关于从asp.net按钮单击打开Sitecore的媒体库编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆