.NET添加多个附件的代码

 

多个附件一起上传 处理 入库等操作

 

.aspx文件中的代码:

 

<head runat="server">

       <script type="text/javascript" >

            function AddAttachments()

            {

                  document.getElementById('attach').value = "继续添加附件";

                  

                  tb = document.getElementById('attAchments');                 

                  newRow = tb.insertRow();

                  newRow.insertCell().innerHTML = "<input name='File' size='50' type='file'>&nbsp;&nbsp;<input type=button value='删除'class='Button_2'style='margin-top:-8px;' οnclick='delFile(this.parentElement.parentElement.rowIndex)'>";

            }

            function delFile(index)

            {

                  document.getElementById('attAchments').deleteRow(index);

                  tb.rows.length > 0?document.getElementById('attach').innerText = "继续添加附件":document.getElementById('attach').value = "添加附件";

            }

            </script>

     <script type="text/javascript">

<!--。。。。省略 其他代码-->

</head>

<body>

<form id="form1"  method="post" runat="server" target="_self" enctype="multipart/form-data" >

<!--。。。。省略 其他代码-->

 

 

<table width="100%" cellpadding="0"  cellspacing="0" border="0"><tr style="display:none;"><td style="height: 21px"></td></tr><tr><td>

                               <div style="text-align:right; width:457px; height: 13px; vertical-align:middle; padding-top:2px" class="tishi_a" >

                                 

                                          <input id="attach" type="button"  style="font-family:宋体;font-size:9pt; height: 23px;"  onclick="AddAttachments();" name="attach"  value="添加附件"  class="Button_6" /></div>

                                </td></tr></table> 

 

 

<!--。。。。省略 其他代码-->

    </form>

</body>

 

.cs代码文件的内容

  //发送信息的附件操作

    private bool saveAccess()

    {

        bool IsOK = false;

        try

        {

            AccessoryModel accesMidel = new AccessoryModel();//这是一个附件所需的数据模型(下面有模型代码)

            AccessoryBLL accesbll = new AccessoryBLL();//这是调用数据库的方法的逻辑层对象

            for (int i = 0; i < Request.Files.Count; i++)

            {

                if (Request.Files[i].ContentLength > 0)

                {

                    fjid = Guid.NewGuid();

                    accesMidel.Id = fjid.ToString();

                    accesMidel.buffers = DBCOM.FileToByte.FilesToBytes(Request.Files[i]);

                    accesMidel.Content = accesMidel.buffers;

                    accesMidel.Title = Request.Files[i].FileName.Substring(Request.Files[i].FileName.LastIndexOf("//") + 1);

                    accesMidel.Msg_Id = xxid.ToString ();//信息id

                    accesMidel.Suffix = Request.Files[i].FileName.Substring(Request.Files[i].FileName.LastIndexOf(".") + 1);

                    accesMidel.Size = float.Parse(Request.Files[i].ContentLength.ToString());

                    accesMidel.Explain = text_AcceExplain.Text.Trim();

                    accesMidel.UpLDate = System.DateTime.Now;

                    accesMidel.Remark = string.Empty;

                    accesMidel.Type = 1;//标示为政务信息的附件

                    if (accesbll.saveAccessory(accesMidel))

                    {

                        IsOK = true;

                    }

                    else

                    {

                        IsOK = false;

                    }

                }

            }

        }

        catch (Exception exx)

        {

            //Response.Write("<script language='javascript'>alert('" +  + "');</" + "script>");

            LTP.Common.MessageBox.Show(this, exx.ToString());

        }

        return IsOK;

    }

 

附模型代码:

namespace Model

{

    public class AccessoryModel

    {

        private Byte[] _buffer;

        private string _Id;

        private string _Title;

        private string _Msg_Id;

        private Byte [] _Content;

        private string _Suffix;

        private float _Size;

        private string _Explain;

        private DateTime _UpLDate;

        private string _Remark;

        private int _Type;

 

        public Byte[] buffers

        {

            get { return _buffer; }

            set { _buffer = value; }

        }

        /// <summary>

        /// 附件ID

        /// </summary>

        public string Id

        {

            get { return _Id; }

            set { _Id = value; }

        }

        /// <summary>

        /// 附件标题

        /// </summary>

        public string Title

        {

            get { return _Title; }

            set { _Title = value; }

        }

        /// <summary>

        /// 回复

        /// </summary>

        public string Msg_Id

        {

            get { return _Msg_Id; }

            set { _Msg_Id = value; }

        }

        /// <summary>

        /// 后缀

        /// </summary>

        public string Suffix

        {

            get { return _Suffix; }

            set { _Suffix = value; }

        }

        /// <summary>

        /// 附件内容

        /// </summary>

        public Byte[] Content

        {

            get { return _Content; }

            set { _Content = value; }

        }

        /// <summary>

        /// 附件大小

        /// </summary>

        public float Size

        {

            get { return _Size; }

            set { _Size = value; }

        }

        /// <summary>

        /// 附件说明

        /// </summary>

        public string Explain

        {

            get { return _Explain; }

            set { _Explain = value; }

        }

        /// <summary>

        /// 上传时间

        /// </summary>

        public DateTime UpLDate

        {

            get { return _UpLDate; }

            set { _UpLDate = value; }

        }

        /// <summary>

        /// 备注

        /// </summary>

        public string Remark

        {

            get { return _Remark; }

            set { _Remark = value; }

        }

 

        /// <summary>

        /// 附件类型为通知企业的附件

        /// </summary>

        public int Type

        {

            get { return _Type; }

            set { _Type = value; }

        }

    }

}

 

如有疑问请留言或提问我们将尽快答复

详情请见http://www.lvtaostudio.com

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值