protected void RolePropertyEdit_PrepareDownloadStream(object sender, PrepareDownloadStreamEventArgs args)
		{
			bool roleAsPerson = false;
			string[] itemsInfio = args.DownloadInfo.RequestContext.Split(';');
			Boolean.TryParse(itemsInfio[1], out roleAsPerson);

			string downloadkey = itemsInfio[0];
			WfMatrix matrix = WfMatrixAdapter.Instance.Load(downloadkey);
			matrix.Loaded = true;

			using (MemoryStream excelStream = matrix.ExportToExcel2007(roleAsPerson))
			{
				excelStream.CopyTo(args.OutputStream);
			}
		}
Example #2
0
        /// <summary>
        /// 下载模板或已存在的文件
        /// </summary>
        public static void Download(object sender, BeforeFileDownloadHandler beforeDownloadHandler, PrepareDownloadStreamHandler prepareDownloadStreamHandler, bool raiseEvent)
        {
            ObjectContextCache.Instance["FileUploadProcessed"] = true;

            HttpResponse response = HttpContext.Current.Response;

            bool fileReadonly = WebUtility.GetRequestQueryValue <bool>("fileReadonly", false);

            string materialID = string.Empty;

            try
            {
                string controlID = WebUtility.GetRequestQueryValue("controlID", string.Empty);

                FileDownloadInfo downloadInfo = FileDownloadInfo.CollectInfoFromRequest();

                if (File.Exists(downloadInfo.FileFullPath) == false)
                {
                    //是否需要启用映射机制(归档后,文件根目录的映射)
                    string mappedRootPath = AppPathMappingContext.GetMappedPathName(downloadInfo.RootPathName);

                    downloadInfo.FileFullPath = GetFileFullPath(downloadInfo.PathType, mappedRootPath, downloadInfo.FilePath);
                }

                response.ContentType = FileConfigHelper.GetFileContentType(downloadInfo.FileName);

                materialID = WebUtility.GetRequestQueryValue("materialID", string.Empty);

                if (materialID.IsNullOrEmpty())
                {
                    materialID = UuidHelper.NewUuidString();
                }

                if (fileReadonly)
                {
                    WebFileOpenMode openMode = FileConfigHelper.GetFileOpenMode(downloadInfo.FileName, downloadInfo.UserID);

                    response.AppendHeader("content-disposition",
                                          string.Format("{0};filename={1}", openMode == WebFileOpenMode.Inline ? "inline" : "attachment", response.EncodeFileNameInContentDisposition(downloadInfo.FileName)));
                }
                else
                {
                    string fileIconPath = FileConfigHelper.GetFileIconPath(downloadInfo.FileName);

                    response.AppendHeader("fileIconPath", HttpUtility.UrlEncode("message=" + fileIconPath));
                    response.AppendHeader("content-disposition", "attachment;fileName=" + response.EncodeFileNameInContentDisposition(downloadInfo.FileName));

                    if (downloadInfo.PathType != PathType.relative)
                    {
                        response.AppendHeader("materialID", "message=" + materialID);
                    }
                }

                bool responseFile = true;

                if (beforeDownloadHandler != null && raiseEvent)
                {
                    responseFile = beforeDownloadHandler(sender, downloadInfo);
                }

                if (responseFile)
                {
                    IMaterialContentPersistManager persistManager =
                        GetMaterialContentPersistManager(materialID, new FileInfo(downloadInfo.FileFullPath));

                    using (Stream stream = persistManager.GetMaterialContent(materialID))
                    {
                        if (prepareDownloadStreamHandler != null && raiseEvent)
                        {
                            PrepareDownloadStreamEventArgs args = new PrepareDownloadStreamEventArgs();

                            args.DownloadInfo = downloadInfo;
                            args.InputStream  = stream;
                            args.OutputStream = response.OutputStream;

                            prepareDownloadStreamHandler(sender, args);
                        }
                        else
                        {
                            stream.CopyTo(response.OutputStream);
                        }
                    }
                }

                Control control = null;

                if (controlID.IsNotEmpty())
                {
                    control = WebControlUtility.FindControlByID((Page)HttpContext.Current.CurrentHandler, controlID, true);
                }

                if (control != null && control is MaterialControl)
                {
                    DownloadEventArgs args = new DownloadEventArgs(materialID, downloadInfo.FilePath);
                    ((MaterialControl)control).OnDownloadFile(args);
                }
            }
            catch (Exception ex)
            {
                if (fileReadonly)
                {
                    response.Write(ex.Message);
                }
                else
                {
                    GenerateErrorInformation(ex.ToString());
                }
            }
            finally
            {
                try
                {
                    response.End();
                }
                catch
                {
                }
            }
        }
        protected void materialCtrl_PrepareDownloadStream(object sender, PrepareDownloadStreamEventArgs args)
        {
            string[] itemsInfo = args.DownloadInfo.RequestContext.Split(';');

            string roleID = itemsInfo[1];
            string defID = itemsInfo[2];

            SOARole role = PrepareRole(roleID, defID);
            WorkBook workBook = role.ToExcelWorkBook();

            using (MemoryStream stream = new MemoryStream())
            {
                workBook.Save(stream);
                stream.Seek(0, SeekOrigin.Begin);
                stream.CopyTo(args.OutputStream);
            }
        }
Example #4
0
		/// <summary>
		/// 下载模板或已存在的文件
		/// </summary>
		public static void Download(object sender, BeforeFileDownloadHandler beforeDownloadHandler, PrepareDownloadStreamHandler prepareDownloadStreamHandler, bool raiseEvent)
		{
			ObjectContextCache.Instance["FileUploadProcessed"] = true;

			HttpResponse response = HttpContext.Current.Response;

			bool fileReadonly = WebUtility.GetRequestQueryValue<bool>("fileReadonly", false);

			string materialID = string.Empty;

			try
			{
				string controlID = WebUtility.GetRequestQueryValue("controlID", string.Empty);

				FileDownloadInfo downloadInfo = FileDownloadInfo.CollectInfoFromRequest();

				if (File.Exists(downloadInfo.FileFullPath) == false)
				{
					//是否需要启用映射机制(归档后,文件根目录的映射)
					string mappedRootPath = AppPathMappingContext.GetMappedPathName(downloadInfo.RootPathName);

					downloadInfo.FileFullPath = GetFileFullPath(downloadInfo.PathType, mappedRootPath, downloadInfo.FilePath);
				}

				response.ContentType = FileConfigHelper.GetFileContentType(downloadInfo.FileName);

				materialID = WebUtility.GetRequestQueryValue("materialID", string.Empty);

				if (materialID.IsNullOrEmpty())
					materialID = UuidHelper.NewUuidString();

				if (fileReadonly)
				{
					WebFileOpenMode openMode = FileConfigHelper.GetFileOpenMode(downloadInfo.FileName, downloadInfo.UserID);

					response.AppendHeader("content-disposition",
						string.Format("{0};filename={1}", openMode == WebFileOpenMode.Inline ? "inline" : "attachment", response.EncodeFileNameInContentDisposition(downloadInfo.FileName)));
				}
				else
				{
					string fileIconPath = FileConfigHelper.GetFileIconPath(downloadInfo.FileName);

					response.AppendHeader("fileIconPath", HttpUtility.UrlEncode("message=" + fileIconPath));
					response.AppendHeader("content-disposition", "attachment;fileName=" + response.EncodeFileNameInContentDisposition(downloadInfo.FileName));

					if (downloadInfo.PathType != PathType.relative)
						response.AppendHeader("materialID", "message=" + materialID);
				}

				bool responseFile = true;

				if (beforeDownloadHandler != null && raiseEvent)
					responseFile = beforeDownloadHandler(sender, downloadInfo);

				if (responseFile)
				{
					IMaterialContentPersistManager persistManager =
						GetMaterialContentPersistManager(materialID, new FileInfo(downloadInfo.FileFullPath));

					using (Stream stream = persistManager.GetMaterialContent(materialID))
					{
						if (prepareDownloadStreamHandler != null && raiseEvent)
						{
							PrepareDownloadStreamEventArgs args = new PrepareDownloadStreamEventArgs();

							args.DownloadInfo = downloadInfo;
							args.InputStream = stream;
							args.OutputStream = response.OutputStream;

							prepareDownloadStreamHandler(sender, args);
						}
						else
						{
							stream.CopyTo(response.OutputStream);
						}
					}
				}

				Control control = null;

				if (controlID.IsNotEmpty())
					control = WebControlUtility.FindControlByID((Page)HttpContext.Current.CurrentHandler, controlID, true);

				if (control != null && control is MaterialControl)
				{
					DownloadEventArgs args = new DownloadEventArgs(materialID, downloadInfo.FilePath);
					((MaterialControl)control).OnDownloadFile(args);
				}
			}
			catch (Exception ex)
			{
				if (fileReadonly)
					response.Write(ex.Message);
				else
					GenerateErrorInformation(ex.ToString());
			}
			finally
			{
				try
				{
					response.End();
				}
				catch
				{
				}
			}
		}