Ejemplo n.º 1
0
        /*
         * protected void LinkButton1_Click(object sender, EventArgs e)
         * {
         * //多图片上传
         *  int count = 0;
         *  if (Session["flashFiles"] != null)
         *  {
         *      string photoPath = Session["flashFiles"] as string;
         *      if (photoPath.Contains(","))
         *      {
         *          string[] photoPathTeam = photoPath.Split(',');
         *          foreach (string path in photoPathTeam)
         *          {
         *              InsertAttachment(path);
         *              count++;
         *          }
         *      }
         *      else
         *      {
         *          InsertAttachment(photoPath);
         *          count++;
         *      }
         *  }
         *  Session["flashFiles"] = null;
         *  string rawurl = We7Helper.RemoveParamFromUrl(Request.RawUrl, "saved");
         *  rawurl = We7Helper.AddParamToUrl(rawurl, "saved", "1");
         *  rawurl = We7Helper.AddParamToUrl(rawurl, "count", count.ToString());
         *  Response.Redirect(rawurl);
         * }
         * */

        void InsertAttachment(string path)
        {
            Attachment a  = new Attachment();
            string     ap = Server.MapPath(path);

            a.FileName  = Path.GetFileName(ap);
            a.FileType  = Path.GetExtension(ap);
            a.FilePath  = path.Replace("/" + a.FileName, "");
            a.ArticleID = ArticleID;
            int type = (int)ArticleAttachment.ArticlePhoto;

            a.EnumState = type.ToString();
            AttachmentHelper.AddAttachment(a);
        }
Ejemplo n.º 2
0
        void ArticleAttachmentFileUpload()
        {
            if (AttachmentFileUpload.FileName.Length < 1)
            {
                Messages.ShowError("附件不能为空!");
                return;
            }
            if (CDHelper.CanUploadAttachment(AttachmentFileUpload.FileName))
            {
                Messages.ShowError("不支持上传该类型的文件。");
                return;
            }
            string ap = GenerateFileName(Path.GetFileName(AttachmentFileUpload.FileName));

            try
            {
                AttachmentFileUpload.SaveAs(ap);
            }
            catch (IOException ex)
            {
                Messages.ShowError("附件上传失败!" + ex.Message);
                return;
            }

            Attachment a = new Attachment();

            a.FileName  = Path.GetFileName(ap);
            a.FilePath  = GetAttachmentPath();
            a.FileSize  = AttachmentFileUpload.PostedFile.ContentLength;
            a.FileType  = Path.GetExtension(ap);
            a.ArticleID = ArticleID;
            AttachmentHelper.AddAttachment(a);
            string rawurl = We7Helper.RemoveParamFromUrl(Request.RawUrl, "saved");

            rawurl = We7Helper.AddParamToUrl(rawurl, "saved", "1");
            Response.Redirect(rawurl);
        }