コード例 #1
0
        /// <summary>
        /// 附件添加
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static Attachment AttachmentUpload(HttpPostedFileBase postfile)
        {
            IESFile file = Upload(postfile);

            if (file.FileGuid != null && file.FileGuid != string.Empty)
            {
                if (RemoteFileExists(file))
                {
                    AttachmentBLL bll        = new AttachmentBLL();
                    Attachment    attachment = new Attachment
                    {
                        FileName  = file.FileName,
                        ServerID  = file.ServerID,
                        FileSize  = file.FileSize,
                        Title     = file.FileTitle,
                        Guid      = file.FileGuid,
                        Source    = string.Empty,
                        SourceID  = 0,
                        RefFileID = "0"
                    };
                    if (bll.Attachment_ADD(attachment))
                    {
                        return(attachment);
                    }
                }
            }
            return(new Attachment());
        }
コード例 #2
0
        /// <summary>
        /// 附件添加
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static List <Attachment> AttachmentUpload()
        {
            HttpFileCollection files          = HttpContext.Current.Request.Files;
            List <Attachment>  attachmentlist = new List <Attachment>();

            for (int i = 0; i < files.Count; i++)
            {
                IESFile file = Upload(files[i]);
                if (file.FileGuid != null && file.FileGuid != string.Empty)
                {
                    if (RemoteFileExists(file))
                    {
                        AttachmentBLL bll = new AttachmentBLL();

                        Attachment attachment = new Attachment
                        {
                            FileName  = file.FileName,
                            ServerID  = file.ServerID,
                            FileSize  = file.FileSize,
                            Title     = file.FileTitle,
                            Guid      = file.FileGuid,
                            Source    = string.Empty,
                            SourceID  = 0,
                            RefFileID = "0"
                        };
                        if (bll.Attachment_ADD(attachment))
                        {
                            attachmentlist.Add(attachment);
                        }
                    }
                }
            }
            return(attachmentlist);
        }
コード例 #3
0
        /// <summary>
        /// 资料上传
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static List <IES.Resource.Model.File> ResourceFileUpload(IES.Resource.Model.File model)
        {
            HttpFileCollection             files            = HttpContext.Current.Request.Files;
            List <IES.Resource.Model.File> resourcefilelist = new List <IES.Resource.Model.File>();

            for (int i = 0; i < files.Count; i++)
            {
                IESFile file = Upload(files[i]);
                if (file.FileGuid != null && file.FileGuid != string.Empty)
                {
                    if (RemoteFileExists(file))
                    {
                        FileBLL bll = new FileBLL();
                        file.FileType = file.GetFileType();
                        IES.Resource.Model.File resourcefile = new IES.Resource.Model.File
                        {
                            FileName       = file.FileName,
                            ServerID       = file.ServerID,
                            FileSize       = file.FileSize,
                            FileTitle      = file.FileTitle,
                            OCID           = model.OCID,
                            FolderID       = model.FolderID,
                            CourseID       = model.CourseID,
                            CreateUserID   = UserService.CurrentUser.UserID,
                            CreateUserName = UserService.CurrentUser.UserName,
                            Ext            = file.Ext,
                            FileType       = file.FileType,
                            ShareRange     = model.ShareRange
                        };
                        resourcefile = bll.File_ADD(resourcefile);
                        if (resourcefile.FileID > 0)
                        {
                            resourcefilelist.Add(resourcefile);
                        }
                    }
                }
            }
            return(resourcefilelist);
        }
コード例 #4
0
        private static IESFile _upload(Stream inputStream, string fileName)
        {
            ResourceServer server = StoreServie.ResourceServer_Fast_Get();

            string machineName = server.Host;
            string httpPort    = server.IISPort;
            string webFolder   = server.IISFolder;
            string PubKey      = server.PubKey;

            string filehead    = Guid.NewGuid().ToString();
            string Ext         = Path.GetExtension(fileName);
            string newFileName = filehead + Ext;

            string code = IES.Common.Secret.Hash.GetMD5(newFileName + PubKey + server.ServerID.ToString());


            string uri = string.Format("http://{0}:{1}/{2}/HttpUpload/HttpUpload.ashx?code={3}&fileName={4}&UName=able&PWD=able&SID={5}",
                                       machineName, httpPort, webFolder, code, newFileName, server.ServerID.ToString());

            HttpWebRequest webRequest = WebRequest.Create(uri) as HttpWebRequest;

            webRequest.ContentType               = "application/x-www-form-urlencoded";
            webRequest.ContentLength             = inputStream.Length;
            webRequest.Timeout                   = 99999999;
            webRequest.Method                    = "POST";
            webRequest.AllowWriteStreamBuffering = false;

            bool iscorrect = true;

            using (Stream fStream = inputStream)
            {
                using (Stream requestStream = webRequest.GetRequestStream())
                {
                    try
                    {
                        byte[] buff = new byte[40960];
                        int    len  = 0;
                        while ((len = fStream.Read(buff, 0, buff.Length)) > 0)
                        {
                            requestStream.Write(buff, 0, len);
                            fStream.Flush();
                            requestStream.Flush();
                        }
                        WebResponse webResponse = webRequest.GetResponse();
                    }
                    catch
                    {
                        iscorrect = false;
                    }
                }
            }
            IESFile file = new IESFile();

            if (iscorrect)
            {
                file.ServerID  = server.ServerID;
                file.FileName  = newFileName;
                file.FileGuid  = filehead;
                file.UserID    = UserService.CurrentUser.UserID;
                file.FileSize  = webRequest.ContentLength;
                file.FileTitle = fileName;
                file.Ext       = Ext;
            }
            return(file);
        }