Exemple #1
0
        /// <summary>保存附件信息</summary>
        public static void Upload(IAttachmentFileInfo file)
        {
            // -------------------------------------------------------
            // 保存 数据库
            // 数据库 支持数据库集群
            // -------------------------------------------------------

            if (AttachmentStorageConfigurationView.Instance.DistributedFileStorageMode == "ON")
            {
                DistributedFileInfo param = new DistributedFileInfo();

                param.Id          = file.Id;
                param.VirtualPath = file.VirtualPath;
                param.FileData    = file.FileData;

                AttachmentStorageContext.Instance.AttachmentDistributedFileService.Save(param);
            }

            // -------------------------------------------------------
            // 保存 二进制数据
            // -------------------------------------------------------

            string path = UploadPathHelper.CombinePhysicalPath(file.Parent.AttachmentFolder, string.Format("{0}{1}", file.Id, file.FileType));

            if (!File.Exists(path))
            {
                UploadPathHelper.TryCreateDirectory(path);

                ByteHelper.ToFile(file.FileData, path);
            }
        }
Exemple #2
0
        /// <summary>获取附件信息</summary>
        public static byte[] Download(IAttachmentFileInfo file)
        {
            DistributedFileInfo param = AttachmentStorageContext.Instance.AttachmentDistributedFileService.FindOne(file.Id);

            if (param == null)
            {
                return(null);
            }
            else
            {
                string path = file.VirtualPath.Replace("{uploads}", AttachmentStorageConfigurationView.Instance.PhysicalUploadFolder);

                UploadPathHelper.TryCreateDirectory(path);

                ByteHelper.ToFile(param.FileData, path);

                return(param.FileData);
            }
        }
Exemple #3
0
        /// <summary>保存附件信息</summary>
        public void Save()
        {
            AttachmentStorageContext.Instance.AttachmentFileService.Save(this);

            // -------------------------------------------------------
            // 保存 二进制数据
            // -------------------------------------------------------

            string path = UploadPathHelper.CombinePhysicalPath(Parent.AttachmentFolder, string.Format("{0}{1}", Id, FileType));

            UploadPathHelper.TryCreateDirectory(path);

            ByteHelper.ToFile(FileData, path);

            // -------------------------------------------------------
            // 保存 二进制信息
            // -------------------------------------------------------

            DistributedFileStorage.Upload(this);
        }