Sitcore Download MediaLibrary Source

 public partial class Download : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!String.IsNullOrEmpty(Request["mid"]))
                {
                    MediaItem mi = Sitecore.Context.Database.GetItem(new ID(Request["mid"]));
                    Stream fileStream = mi.GetMediaStream();
                    byte[] buffer = new byte[fileStream.Length];
                    fileStream.Read(buffer, 0, (int)fileStream.Length);
                    fileStream.Close();
                    Response.ContentType = mi.MimeType;
                    Response.AddHeader("content-disposition", "attachment; filename=" + mi.DisplayName + "." + mi.Extension);
                    Response.BinaryWrite(buffer);
                    Response.Flush();
                    Response.End();
                }
                else
                {

                    if (String.IsNullOrEmpty(Request["fileUrl"]) || String.IsNullOrEmpty(Request["fileType"]))
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "script", "<script type=‘text/javascript‘>alert(‘下载失败‘);window.opener=null;window.open(‘‘,‘_self‘); window.close();</script>");
                    }
                    else
                    {
                        string url = "http://" + System.Web.HttpContext.Current.Request.Url.Host.ToString() + ":" + System.Web.HttpContext.Current.Request.Url.Port.ToString() + Request["fileUrl"];
                        WebClient my = new WebClient();
                        byte[] mybyte;
                        mybyte = my.DownloadData(url);
                        MemoryStream ms = new MemoryStream(mybyte);
                        //下面直接输出
                        Response.ClearContent();
                        Response.ContentType = "application/x-msdownload";
                        string filename = "attachment; filename=" + DateTime.Now.ToString("yyyyMMddHHmmssffff") + Request["fileType"];
                        Response.AddHeader("Content-Disposition", filename);
                        Response.BinaryWrite(mybyte);
                        Response.Flush();
                        Response.End();
                    }
                }
            }
            catch
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "script", "<script type=‘text/javascript‘>alert(‘下载失败‘);window.opener=null;window.open(‘‘,‘_self‘); window.close();</script>");
            }
        }
    }
时间: 2024-11-05 06:04:31

Sitcore Download MediaLibrary Source的相关文章

csharp: Download SVN source

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; using System.Text.RegularExpressions; using System.IO; using System

Downloading the Source

Downloading the Source IN THIS DOCUMENT Installing Repo Initializing a Repo client Downloading the Android Source Tree Using Authentication Troubleshooting network issues Using a local mirror Verifying Git Tags The Android source tree is located in a

Installing Python 3.5.2 from source

Here are the procedures we are to follow, Download the source code of an official Python release. Configure the build appropriately for our machine. Compile the software. Test the software to make sure it works properly. Install the software. Configu

Browse W3C&#39;s Open Source Software

https://www.w3.org/Status.html Browse W3C's Open Source Software Amaya - a Web browser/editor First released Feb '97, Amaya is not just a browser, but a hypertext editor. It's a test-bed for the design of embedded objects, stylesheets, math, structur

Thinking in Java 4th Edition Source Code

Thinking in Java 4th Edition Source Code Instructions for downloading, installing and testing the source code Download the source code zip file from this link. Create a directory in which to install the code. For these instructions, we'll refer to th

Install MySQL 5.7.5-m15 on Ubuntu Server 14.04 LTS from Source

This post documents the steps of installing MySQL from source code, and the resolutions to serveral issues in installing. The steps here are specific to 64-bit Ubuntu 14.04.1 LTS, and MySQL source code is 5.7.5-m15. But I think most of them can also 

Install Git from Latest Source on Ubuntu

Install dependencies sudo apt-get update sudo apt-get install libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext Download Git source code wget https://github.com/git/git/archive/master.zip Unzip and install If you have not unzip installed on your s

Redis(三)源source编译

背景: 自己电脑是win7 32bit的,而想要Redis4.0的版本,但是在网上没找到,所以自己干脆download源source,自己build,安装. 最后,目前达到的状态是,windows下source编译失败,无法成功安装,lunix下source编译成功,安装成功. 接下来自己,记录一下,这个过程踩的雷,碰到的坑,也不枉自己花了两个晚上,弄出来的东西. 说说自己windows下的source编译 1.Git 首先安装了一个,Git,官网上可以很容易找到地址. 安装步骤如下: 这之后点

How to Build MySQL from Source Code on Windows & compile MySQL on win7+vs2010

Not counting obtaining the source code, and once you have the prerequisites satisfied, [Windows] users can build from source code in 5 easy steps. Prerequisites – Install & ensure they are in the $PATH: CMake <-- Download C++ compiler <-- Visual