Exemplo n.º 1
0
        /// <summary>
        /// 上传附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpAttach_Click(object sender, EventArgs e)
        {
            string sourceFolder = Path.Combine(WebUI.UIBiz.CommonInfo.ImageRootPath, this.hiFolder.Value);

            sourceFolder = Path.Combine(sourceFolder, UIBiz.CommonInfo.AttachFolder);

            if (!Directory.Exists(sourceFolder))
            {
                Directory.CreateDirectory(sourceFolder);
            }

            string fileType = Path.GetExtension(this.attachFile.FileName);
            string fileName = Path.GetFileName(this.attachFile.FileName);
            //string NewfileName = fileName + fileType;

            string fileFullPath = Path.Combine(sourceFolder, fileName);

            if (fileName.Length > 255)
            {
                ShowMessage("附件名称过长,需小于255个字符!");
                return;
            }

            if (File.Exists(fileFullPath))
            {
                ShowMessage("附件名称重复,请删除原有附件重新上传!");
                return;
            }

            try
            {
                this.attachFile.SaveAs(fileFullPath);

                if (ImageStorageClass.AddAttach(new Guid(this.Hidden_ImgItemId.Value), fileName))
                {
                    ShowMessage("添加附件成功!");
                    LoadAttach();
                }
                else
                {
                    ShowMessage("添加附件失败!");
                }
            }
            catch (PathTooLongException pe)
            {
                ShowMessage("附件名称过长!");
            }
        }