예제 #1
0
 public static void InitFileLoad(string strApplicationID, FormTypes action, FileUpLoad.FileControl control, bool AllowDelete)
 {
     SMT.FileUpLoad.Classes.UserConfig uc = new SMT.FileUpLoad.Classes.UserConfig();
     uc.CompanyCode = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.UserPosts[0].CompanyID;
     uc.SystemCode = "WF";
     uc.ModelCode = "FLOW_FLOWRECORDDETAIL_T";
     uc.UserID = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.EmployeeID;
     uc.ApplicationID = strApplicationID;
     uc.NotShowThumbailChckBox = true;
     if (action == FormTypes.Browse || action == FormTypes.Audit)
     {
         uc.NotShowUploadButton = true;
         uc.NotShowDeleteButton = true;
         uc.NotAllowDelete = true;
     }
     if (!AllowDelete)
     {
         uc.NotShowDeleteButton = true;
     }
     uc.Multiselect = true;
     uc.Filter = "所有文件 (*.*)|*.*";
     //uc.Filter = "图片文件(*.jpg,*.gif,*.bmp)|*.jpg;*.gif;*.bmp";
     uc.MaxConcurrentUploads = 5;
     uc.MaxSize = "20.MB";
     uc.CreateName = SMT.SAAS.Main.CurrentContext.Common.CurrentLoginUserInfo.EmployeeName;
     uc.PageSize = 20;
     control.Init(uc);
 }
예제 #2
0
    public string UpLoadFile(HttpPostedFile inputFile, string filePath, string myfileName)
    {
        if (string.IsNullOrEmpty(filePath))
        {
            throw new ApplicationException("路径不能为空");
        }
        if (string.IsNullOrEmpty(myfileName))
        {
            throw new ApplicationException("文件名不能为空");
        }
        FileUpLoad fp = new FileUpLoad();

        //建立上传对象
        HttpPostedFile postedFile = inputFile;

        FileName = System.IO.Path.GetFileName(postedFile.FileName);
        FileExtension = System.IO.Path.GetExtension(FileName).ToUpper();

        //如果格式都不符合则返回
        if (!".JPG".Equals(FileExtension) && !".JPEG".Equals(FileExtension) && !".PNG".Equals(FileExtension) )
        {
            throw new ApplicationException("上传图片格式正确,请选择jpg,png格式的图片");
        }
        if (postedFile.ContentLength > 1024 * 1024 * 20)
        {
            throw new ApplicationException("最大只能上传20M文件");
        }

        if (myfileName != string.Empty)
        {
            FileName = myfileName+FileExtension;
        }

        string phyPath = HttpContext.Current.Server.MapPath("upload");

        //判断路径是否存在,若不存在则创建路径
        DirectoryInfo upDir = new DirectoryInfo(phyPath);
        if (!upDir.Exists)
        {
            upDir.Create();
        }

        try
        {
            string tempPath = Path.Combine(phyPath, filePath);
            string originalImagePath = Path.Combine(tempPath, FileName);
            string thumbnailPath = Path.Combine(tempPath,"thumbnail_" + FileName);
            //保存源文件
            postedFile.SaveAs(originalImagePath);

            ImageHelper.MakeThumbnail(originalImagePath, thumbnailPath,80,80,"W");
        }
        catch
        {
            throw new ApplicationException("上传失败!");
        }
        return "/upload/" + filePath + "/thumbnail_" + FileName;
    }
예제 #3
0
        public void getAllFile()
        {
            string            access_token = (string)Session["access_token"];
            List <FileUpLoad> files        = new List <FileUpLoad>();
            //先得到有多少数量
            int total = FileUpLoad.getNum(access_token);
            //再根据数量来一个一个读取信息
            JObject jo = FileUpLoad.getAllFile(access_token);

            for (int i = 0; i < total; i++)
            {
                FileUpLoad item = FileUpLoad.getItem(jo, i);

                files.Add(item);
            }
            Files.DataSource = files;
            Files.DataBind();
        }
        public void Upload([FromForm] FileUpLoad objfile)
        {
            //bbbbbbbbbbbb
            //cccccccccccc
            //dddddddddddd
            var uploads = Path.Combine(Directory.GetCurrentDirectory(), "uploads");

            if (!Directory.Exists(uploads))
            {
                Directory.CreateDirectory(uploads);
            }
            if (objfile.file.Length > 0)
            {
                var filePath = Path.Combine(uploads, objfile.file.FileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    objfile.file.CopyTo(fileStream);
                }
            }
        }
예제 #5
0
        public ActionResult AsyncUpload(bool minimalMode = false, string fieldName = null)
        {
            var postedFile = Request.ToPostedFileResult();

            if (postedFile == null)
            {
                throw new ArgumentException("No file uploaded");
            }
            string fileNameKey = Guid.NewGuid().ToString();

            postedFile.FileName = fileNameKey + postedFile.FileExtension;
            string filePath = FileUpLoad.FileSaveAs(postedFile, this._webSiteContext.CurrentSite.Id.ToString());

            var download = new Download
            {
                DownloadGuid   = Guid.NewGuid(),
                UseDownloadUrl = true,
                DownloadUrl    = filePath,
                //DownloadBinary = postedFile.Buffer,
                ContentType = postedFile.ContentType,
                // we store filename without extension for downloads
                Filename    = postedFile.FileTitle,
                Extension   = postedFile.FileExtension,
                IsNew       = true,
                IsTransient = true
            };

            _downloadService.InsertDownload(download);

            return(Json(new
            {
                success = true,
                downloadId = download.Id,
                fileName = download.Filename + download.Extension,
                downloadUrl = Url.Action("DownloadFile", new { downloadId = download.Id }),
                html = this.RenderPartialViewToString(TEMPLATE, download.Id, new { minimalMode = minimalMode, fieldName = fieldName })
            }));
        }
예제 #6
0
      /// <summary>
 /// 新上传控件调用
 /// </summary>
 /// <param name="strModelCode">模块编码,一般为表名</param>
 /// <param name="strApplicationID">表单ID</param>
 /// <param name="action">动作</param>
 /// <param name="control">上传控件</param>
 /// <param name="AllowDelete">是否允许删除</param>
 public static void InitFileLoad(string strApplicationID, ViewState action, FileUpLoad.FileControl control, bool AllowDelete)
 {
     SMT.FileUpLoad.Classes.UserConfig uc = new SMT.FileUpLoad.Classes.UserConfig();
     uc.CompanyCode = Common.CurrentLoginUserInfo.UserPosts[0].CompanyID;
     uc.SystemCode = "Platform";
     uc.ModelCode = "News";
     uc.UserID = Common.CurrentLoginUserInfo.EmployeeID;
     uc.ApplicationID = strApplicationID;
     uc.NotShowThumbailChckBox = true;
     //if (action == ViewState.Browse || action == ViewState.Audit)
     //{
     //    uc.NotShowUploadButton = true;
     //    uc.NotShowDeleteButton = true;
     //    uc.NotAllowDelete = true;
     //}
     if (!AllowDelete)
     {
         uc.NotShowDeleteButton = true;
     }
     uc.Multiselect = true;
     uc.Filter = "图片文件(*.png, *.jpg)|*.png;*.jpg";
     //uc.Filter = "图片文件(*.jpg,*.gif,*.bmp)|*.jpg;*.gif;*.bmp";
     uc.MaxConcurrentUploads = 1;
     uc.MaxSize = "20.MB";
     uc.CreateName = Common.CurrentLoginUserInfo.EmployeeName;
     uc.PageSize = 20;
     control.Init(uc);
 }
예제 #7
0
        public void UpLoad1(object sender, EventArgs e)
        {
            //指定上传文件在服务器上的保存路径
            //取出所选文件的本地路径
            string fullFileName = this.UpLoad.PostedFile.FileName;
            //从路径中截取出文件名
            string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);
            //限定上传文件的格式
            string type    = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);
            int    FileLen = UpLoad.PostedFile.ContentLength / 1024;//获取上传文件的大小

            MessageBox.Show(FileLen + "");
            if (FileLen > 1024 * 1024 * 1)
            {
                MessageBox.Show("最大上传1G文件");
                return;
            }
            string savePath = Server.MapPath("~/files/" + Session["num"].ToString());

            //MessageBox.Show(savePath);
            //将文件保存在服务器中根目录下的files文件夹中
            if (!System.IO.Directory.Exists(savePath))
            {
                //MessageBox.Show("不存在");
                System.IO.Directory.CreateDirectory(savePath);
            }
            //将filename换成时间。
            DateTime time       = DateTime.Now;
            string   year       = time.Year.ToString();
            string   month      = time.Month.ToString();
            string   day        = time.Day.ToString();
            string   hour       = time.Hour.ToString();
            string   minute     = time.Minute.ToString();
            string   second     = time.Second.ToString();
            string   filename_1 = year + month + day + hour + minute + second + fileName;
            //MessageBox.Show(filename_1);
            string saveFileName = savePath + "\\" + filename_1;

            UpLoad.SaveAs(saveFileName);
            //向数据库中存储相应通知的附件的目录
            FileUpLoad file = new FileUpLoad();

            //创建附件的实体
            file.name     = fileName;               //附件名
            file.sendName = Session["name"].ToString();
            file.num      = Session["num"].ToString();
            file.date     = time;       //上传文件的时间
            file.filename = filename_1; //用时间+文件名来表示
            //file.id = id;
            string access_token = (string)Session["access_token"];

            if (file.upload(access_token))
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('文件上传成功!');</script>");
                getAllFile();
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('文件上传失败!');</script>");
            }
        }
예제 #8
0
파일: Utility.cs 프로젝트: JuRogn/OA
 public static void InitFileLoad(string strModelCode, string strApplicationID, FormTypes action, FileUpLoad.FileControl control)
 {
     InitFileLoad(strModelCode, strApplicationID, action, control, true);
 }
예제 #9
0
    public FileUpLoad UpLoadFile(HtmlInputFile InputFile, string filePath, string myfileName, bool isRandom)
    {
        FileUpLoad fp = new FileUpLoad();
        string fileName, fileExtension;
        string saveName;

        //
        //建立上传对象
        //
        HttpPostedFile postedFile = InputFile.PostedFile;

        fileName = System.IO.Path.GetFileName(postedFile.FileName);
        fileExtension = System.IO.Path.GetExtension(fileName);

        //
        //根据类型确定文件格式
        //
        string format = "xlsx";

        //
        //如果格式都不符合则返回
        //
        if (format.IndexOf(fileExtension) == -1)
        {
            throw new ApplicationException("上传数据格式不合法");
        }

        //
        //根据日期和随机数生成随机的文件名
        //
        if (myfileName != string.Empty)
        {
            fileName = myfileName;
        }

        if (isRandom)
        {
            Random objRand = new Random();
            System.DateTime date = DateTime.Now;
            //生成随机文件名
            saveName = date.Year.ToString() + date.Month.ToString() + date.Day.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + Convert.ToString(objRand.Next(99) * 97 + 100);
            fileName = saveName + fileExtension;
        }

        string phyPath = HttpContext.Current.Request.MapPath(filePath);

        //判断路径是否存在,若不存在则创建路径
        DirectoryInfo upDir = new DirectoryInfo(phyPath);
        if (!upDir.Exists)
        {
            upDir.Create();
        }

        //
        //保存文件
        //
        try
        {
            postedFile.SaveAs(phyPath + fileName);

            fp.FilePath = filePath + fileName;
            fp.FileExtension = fileExtension;
            fp.FileName = fileName;
        }
        catch
        {
            throw new ApplicationException("上传失败!");
        }

        //返回上传文件的信息
        return fp;
    }
예제 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="File">上传的文件</param>
        /// <param name="ReadUser">上传文件谁可以读取?</param>
        /// <returns></returns>
        public async Task <ReturnType> FileUpLoadToAliyunOSSAsync(IFormFile File, User User)
        {
            if (File == null)
            {
                throw new ErrorException(1, "文件为空");
            }
            IPicProcess PicProcess = new ImageProcessTwo();

            //这次文件保存使用了阿里云OSS,所以,
            //主机内只保存缩略图即可,只有用户需要大图时,才将完整图片链接显示出来

            //检查文件类型
            string Type = File.ContentType;

            if (PicProcess.FileTypeCheck(Type))
            {
                // 进行文件名处理,得到文件名
                string FileName = PicProcess.CreateFileName(File.FileName);
                // 生成各个文件的路径
                var FilePath_Image       = Final.FilePath_Image + FileName;       //大缩略图保存
                var FilePath_Image_Thumb = Final.FilePath_Image_Thumb + FileName; //缩略图保存位置

                string TrueFileName;                                              //阿里云OSS的文件Key(包含文件夹的)
                var    IsPublic = false;                                          //是否是公开读取的文件(默认不是)
                try
                {
                    using
                    (
                        Stream stream_img = new FileStream(FilePath_Image, FileMode.Create),
                        stream_img_thumb = new FileStream(FilePath_Image_Thumb, FileMode.Create),
                        stream = File.OpenReadStream()
                    )
                    {
                        FileUpLoad         fileUpLoad         = new FileUpLoad();
                        AliyunImageProcess aliyunImageProcess = new AliyunImageProcess();

                        TrueFileName = fileUpLoad.CreateFileName(FileName, IsPublic);
                        //上传到阿里云OSS
                        fileUpLoad.AliyunFileUpLoad(stream, TrueFileName);
                        //下载缩略图
                        var Process   = "image/auto-orient,1/resize,m_fill,w_400,h_400/quality,q_80/format,jpg";
                        var ossObject = aliyunImageProcess.Process(TrueFileName, Process);
                        await ossObject.Content.CopyToAsync(stream_img_thumb);

                        //下载缩略图的大图
                        var ProcessBig   = "image/auto-orient,1/resize,m_lfit,w_600/quality,q_90/format,jpg";
                        var ossObjectBig = aliyunImageProcess.Process(TrueFileName, ProcessBig);
                        await ossObjectBig.Content.CopyToAsync(stream_img);
                    }

                    MoeTools moeTools = new MoeTools();
                    // 生成Image数据
                    var ReadUsers = moeTools.GetImage_ReadUsers(Public: false, Users: User.Id);

                    Images Image = new Images
                    {
                        ImageName   = File.FileName,
                        ImagePath   = FilePath_Image,//实际大图缩略图的存储位置
                        ReadUsers   = ReadUsers,
                        UpLoadUsers = User,
                        ContentType = Type,
                        StaticPath  = TrueFileName//阿里云Oss的存储路径(key)
                    };

                    Images = Image;

                    return(ReturnType.FileUpLoadOK);
                }
                catch (Exception e)
                {
#if DEBUG
                    Console.WriteLine(e);
#endif
                    //上传文件一般不会发生异常,阿里云的服务器,也不需要对文件类型进行检查了
                    //万一出现异常情况的话,
                    //就删除创建的缩略图文件
                    System.IO.File.Delete(FilePath_Image);           // 删除源文件
                    System.IO.File.Delete(FilePath_Image_Thumb);     // 删除预览图文件

                    throw new ErrorException(2, "发生错误,请稍后重试");       // 抛出异常,到异常页面
                }
            }
            else
            {
                return(ReturnType.AdminLog);
            }
        }