zoukankan      html  css  js  c++  java
  • 图片上传

     protected void btnUpload_Click(object sender, EventArgs e)
            {
                Button btnupload = sender as Button;
                if (btnupload.ID.Equals("btnUpload"))//待补中的上传
                {
                    if (!fuFileUp.HasFile)
                    {
                        //ScriptManager.RegisterClientScriptBlock(this.upAttachment, this.GetType(), "", "alert('请选择要上传的文件!')", true);
                        ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "", "alert('请选择要上传的文件!')", true);
                        return;
                    }
                }
                string strUploadFile = ConfigHelper.GetConfigString("UploadFilePath");

                string remoteFilePath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + strUploadFile.TrimEnd('\\') + "\\" +
                                  "\\Approval\\";
                if (!Directory.Exists(remoteFilePath))
                {
                    Directory.CreateDirectory(remoteFilePath);
                }
                DataRow drNewRow = Attachment.NewRow();///加新行,都临时保存到viewState中
                drNewRow["AttachmentID"] = Guid.NewGuid();
                string strFileName = "";
                string strOrgFileName = "";
                strFileName = "/" + System.DateTime.Now.ToString("yyyyMMdd") + "_" + Guid.NewGuid() + Path.GetExtension(fuFileUp.FileName);
                strOrgFileName = fuFileUp.FileName; //文件名
                fuFileUp.PostedFile.SaveAs(remoteFilePath + strFileName);
                string remoteFileName = "http://www.cnblogs.com/" + strUploadFile + "/Approval" + strFileName;//相对路径
                drNewRow["ReferenceID"] = strInventoryID;
                drNewRow["FileName"] = strOrgFileName;
                drNewRow["FileType"] = strOrgFileName.Substring(strOrgFileName.LastIndexOf("."));
                drNewRow["FileFullName"] = remoteFileName;

                drNewRow["CreateBy"] = GetCurrentUser();
                drNewRow["CreateDate"] = DateTime.Now.ToString();
                drNewRow["ActiveFlag"] = (int)Common.CommonEnum.ActiveFlag.valid;

                Attachment.Rows.Add(drNewRow.ItemArray);
                LoadAttachment();
            }

      protected void rptAttachment_ItemCommand(object source, RepeaterCommandEventArgs e)
            {
                if (e.CommandName.Equals("Delete"))
                {
                    if (Attachment != null && Attachment.Rows.Count > 0)
                    {
                        DataRow[] drs = Attachment.Select("AttachmentID='" + e.CommandArgument.ToString() + "'");
                        if (drs.Length > 0)
                        {
                            drs[0]["ActiveFlag"] = (int)Common.CommonEnum.ActiveFlag.invalid;
                            drs[0]["ModifyBy"] = GetCurrentUser();
                            drs[0]["ModifyDate"] = DateTime.Now.ToString();
                            Attachment.AcceptChanges();

                            MessageBox.Show(this.Page, "删除成功!");
                        }
                    }

                    else
                    {
                        MessageBox.Show(this.Page, "删除失败!");
                    }

                    LoadAttachment();
                }
            }

  • 相关阅读:
    PHP 动态执行
    jenkins 'cordova' command not recognised on Jenkins Windows slave
    ionic3 实现扫码功能
    解决ionic3 android 运行出现Application Error
    解决添加codova plugin 编译出现问题:Execution failed for task ':processDebugManifest'.
    菜鸟的 Sass 学习笔记
    解决关于ios访问相机闪退问题
    解决ios关于:ERROR Internal navigation rejected
    Angular4 组件通讯方法大全
    ASP.NET MVC5 使用MiniProfiler 监控MVC性能
  • 原文地址:https://www.cnblogs.com/sisiblog/p/2932246.html
Copyright © 2011-2022 走看看