コード例 #1
0
 /// <summary>
 /// 附件保存,用于需要把已有信息的附件指定给当前信息的情况
 /// </summary>
 /// <param name="oldInfoID">已有信息的id</param>
 /// <returns></returns>
 public bool Save(string oldInfoID)
 {
     if (this.FunCode != "" && this.InfoID != "")
     {
         //首先保存新附件
         int count = Request.Files.Count;
         HttpPostedFile[] files = new HttpPostedFile[count];
         for (int i = 0; i < count; i++)
         {
             files[i] = (HttpPostedFile)Request.Files[i];
         }
         AccessoriesBLL accessory = new AccessoriesBLL();
         accessory.AddAccessories(this.FunCode, this.InfoID, files);
         //添加从原来信息继承过来的附件
         accessory.Copy(this.FunCode, oldInfoID, this.InfoID);
         //删掉需要删除掉的
         string   deletedID  = this.deleted.Value.ToString();
         string[] deletedIds = deletedID.Split(',');
         foreach (string deletedId in deletedIds)
         {
             if (deletedId != "")
             {
                 accessory.Delete(deletedId);
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
コード例 #2
0
 protected void Down_OnClick(object sender, EventArgs e)
 {
     try
     {
         string         selAccessory = this.selected.Value.ToString();
         AccessoriesBLL accessory    = new AccessoriesBLL();
         Accessories    _accessory   = accessory.Read(selAccessory);
         string         path         = AccessoriesBLL.accessoryPath.ToString() + "\\" + _accessory.NewName;
         FileInfo       file         = new FileInfo(path);
         if (System.IO.File.Exists(path))
         {
             System.Web.HttpContext.Current.Response.Buffer = true;
             System.Web.HttpContext.Current.Response.Clear();
             System.Web.HttpContext.Current.Response.ClearHeaders();
             System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
             System.Web.HttpContext.Current.Response.ContentType     = _accessory.FileType;
             string stroldname = System.Web.HttpUtility.UrlEncode(_accessory.OldFullName);
             System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;  filename=" + stroldname);
             System.Web.HttpContext.Current.Response.AddHeader("Content-Length", _accessory.FileLength.ToString());
             byte[]     tmpbyte = new byte[1024 * 1000];
             FileStream fs      = file.OpenRead();
             int        count;
             while ((count = fs.Read(tmpbyte, 0, tmpbyte.Length)) > 0)
             {
                 System.Web.HttpContext.Current.Response.OutputStream.Write(tmpbyte, 0, count);
                 System.Web.HttpContext.Current.Response.Flush();
             }
             fs.Close();
             System.Web.HttpContext.Current.Response.End();
         }
         else
         {
             //System.Web.HttpContext.Current.Response.Write("");
             lbl_Script.Text = "<script>alert('附件文件不存在,请联系管理员!!');</script>";
             return;
         }
     }
     catch
     {
     }
 }
コード例 #3
0
ファイル: Upload2.ascx.cs プロジェクト: zpf1989/WZCY
    /// <summary>
    /// 附件加载
    /// </summary>
    public void Load()
    {
        if (this.FunCode != "" && this.InfoID != "")
        {
            if (this.ReadOnly)
            {
                string appName = System.Configuration.ConfigurationManager.AppSettings["ApplicationName"];
                fileTable.Rows.Clear();
                appName = appName.TrimEnd('/') + "/OA/UserControl/Down.aspx";
                //this.tableA.Style["display"] = "none";
                //绑定数据并提供下载
                HtmlTableRow   row         = null;
                HtmlTableCell  cell        = null;
                AccessoriesBLL accessory   = new AccessoriesBLL();
                Accessories[]  accessories = accessory.GetAccessories(this.FunCode, this.InfoID);
                int            count       = accessories.Length;

                for (int i = 0; i < count; i++)
                {
                    string path = AccessoriesBLL.accessoryPath.ToString() + "\\" + accessories[i].NewName;
                    row  = new HtmlTableRow();
                    cell = new HtmlTableCell("td");
                    //cell.InnerHtml = "<a href=\"#\"  onclick=\"down(" + accessories[i].ID + ")\" >" + accessories[i].OldFullName + "</a>&nbsp;&nbsp;</td>";
                    cell.InnerHtml = "<a  href=\"" + appName + "?name=" + security.Encrypt(accessories[i].OldFullName, security.se_yaoshi) + "&path=" + security.Encrypt(path, security.se_yaoshi) + "#\"  onclick=\"down(" + accessories[i].Id + ")\" >" + accessories[i].OldFullName + "</a>";
                    string[] args = accessories[i].NewFullName.Split('.');
                    if (args[1].ToString().ToLower() == "pdf")
                    {
                        string tpath = System.Configuration.ConfigurationManager.AppSettings["ApplicationName"] + "/Source/modules/workflow/PdfFolder/" + accessories[i].NewFullName;

                        cell.InnerHtml += "<a href='" + System.Configuration.ConfigurationManager.AppSettings["ApplicationName"] + "/Source/Modules/FileExchange/File/PDFShow.aspx?tpath=" + security.Encrypt(tpath, security.se_yaoshi) + "' target='_blank' >&nbsp;&nbsp;预览</a>";
                    }
                    //  cell.InnerHtml += "</td>";
                    row.Cells.Add(cell);
                    fileTable.Rows.Add(row);
                }
            }
            else
            {
                fileTable.Rows.Clear();
                string appName = System.Configuration.ConfigurationManager.AppSettings["ApplicationName"];
                string phyPath = appName.TrimEnd('/') + "/OA/UserControl/Down.aspx";
                //加载已经上传的附件
                HtmlTableRow   row         = null;
                HtmlTableCell  cell        = null;
                AccessoriesBLL accessory   = new AccessoriesBLL();
                Accessories[]  accessories = accessory.GetAccessories(this.FunCode, this.InfoID);
                int            count       = accessories.Length;
                for (int i = 0; i < count; i++)
                {
                    string path = AccessoriesBLL.accessoryPath.ToString() + "\\" + accessories[i].NewName;
                    row        = new HtmlTableRow();
                    cell       = new HtmlTableCell("td");
                    cell.Align = "left";
                    //cell.InnerHtml = "<a href=\"#\"  onclick=\"down(" + accessories[i].ID + ")\" >" + accessories[i].OldFullName + "</a>&nbsp;&nbsp;<a href='javascript:delTableRow(\"" + (fileTable.Rows.Count) + "\",\"" + accessories[i].ID + "\")'><IMG class=\'uploaddeleteicon\' border='0' /></a></td>";
                    cell.InnerHtml = "<a  href=\"" + phyPath + "?name=" + security.Encrypt(accessories[i].OldFullName, security.se_yaoshi) + "&path=" + security.Encrypt(path, security.se_yaoshi) + "#\"  onclick=\"down(" + accessories[i].Id + ")\" >" + accessories[i].OldFullName + "</a>&nbsp;&nbsp;<a href='javascript:delTableRow(\"" + (fileTable.Rows.Count) + "\",\"" + accessories[i].Id + "\")'></a>";

                    string[] args = accessories[i].NewFullName.Split('.');
                    if (args[1].ToString().ToLower() == "pdf")
                    {
                        string tpath = System.Configuration.ConfigurationManager.AppSettings["ApplicationName"] + "/Source/modules/workflow/PdfFolder/" + accessories[i].NewFullName;
                        cell.InnerHtml += "<a href='" + System.Configuration.ConfigurationManager.AppSettings["ApplicationName"] + "/Source/Modules/FileExchange/File/PDFShow.aspx?tpath=" + security.Encrypt(tpath, security.se_yaoshi) + "\\" + "' target='_blank' >&nbsp;&nbsp;预览</a>";
                    }
                    // cell.InnerHtml += "</td>";

                    row.Cells.Add(cell);
                    fileTable.Rows.Add(row);
                }
            }
        }
    }