文件上传方法

由于时间紧迫无法实现类似126信箱的那种文件上传方法,可是总体的框架已经实现了,

 

<%@ Page Language="C#" AutoEventWireup="true" Codebehind="WebForm2.aspx.cs" Inherits="GloryView.Meeting.Web.Module.admin.MeetingManage.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" method="post" runat="server" enctype="multipart/form-data">
        <table align="center" style="width: 549px">
            <tr>
                <td align="center" style="height: 60px">
                    <h1>
                        多附件上传
                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></h1>
                </td>
            </tr>
            <tr>
                <td id="TD">
                    <button style="width: 79px; height: 20px" type="button" οnmοuseοver="fileAttachmentclick()">
                        继续添加</button>
                    <br />
              
                    <%--<div>
                        <div style='display: none'>
                            <input type="file" id="files" name="files" style='filter: alpha(opacity=0); width: 30px;
                                position: absolute' οnchange='addFiles(this)'>
                        </div>
                    </div>--%>
                    <%-- <input  type="file" name="files" id="files" style="FILTER: alpha(opacity=0); POSITION: absolute; left: 205px; top: 80px;" onChange="addFiles(this)" size="1"><br />--%>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblError" runat="server"></asp:Label>
                    <input id="files1" name="files1" type="file" /></td>
            </tr>
            <tr>
                <td align="center" style="height: 26px">
                    <asp:Button ID="btnUpLoad" runat="server" Text=" 上 传 " EnableViewState="False" CausesValidation="true"
                        OnClick="btnUpLoad_Click" OnLoad="btnUpLoad_Load"></asp:Button>
                </td>
            </tr>
        </table>

        <script language="javascript">
 var count=0;
    function addFiles(file)
    {
//           if( file.value!="")
//           {
//                var sLineHTML="<div><div style='display:none'><input type='file' name='files'  id='files'     style='FILTER: alpha(opacity=0); WIDTH: 30px; POSITION: absolute'  onChange='addFiles(this)'></div><input type='button' οnclick='javascript:delFileInput(this)' value='删除'></div>";
//                document.all["TD"].insertAdjacentHTML('beforeEnd',sLineHTML);
//           }
//        if(file.value=="")
//        {
//             var divToDel=oInputButton.parentNode;
//        divToDel.parentNode.removeChild(divToDel);
//        }
    }
    function delFileInput(oInputButton)
    {
        var divToDel=oInputButton.parentNode;
        divToDel.parentNode.removeChild(divToDel);
    }
    function fileAttachmentclick()
    {
   
        var obj;
         var f=document.getElementsByName("files");
       
        if(f.length==0)
        {
               count+=1;
               var sLineHTML="<div><div style='display:none'><input type='file' name='files'  id='files'     style='FILTER: alpha(opacity=0); WIDTH: 30px; POSITION: absolute'  onChange='addFiles(this)'></div><span id='Label1'></span><input type='button' οnclick='javascript:delFileInput(this)' value='删除'></div>";
                document.all["TD"].insertAdjacentHTML('beforeEnd',sLineHTML);
              
         }
        else
        {
           obj= f[f.length-1];
            if(obj.value!="")
           {
                count+=1;
                var sLineHTML="<div><div style='display:none'><input type='file' name='files'  id='files'     style='FILTER: alpha(opacity=0); WIDTH: 30px; POSITION: absolute'  onChange='addFiles(this)'></div><input type='button' οnclick='javascript:delFileInput(this)' value='删除'></div>";
                document.all["TD"].insertAdjacentHTML('beforeEnd',sLineHTML);
           }          
        }
        f=document.getElementsByName("files");
        obj= f[f.length-1];  
        with(obj)
        {
                style.posTop=event.srcElement.getBoundingClientRect().top
                var x=event.x-offsetWidth/2
                if(x<event.srcElement.getBoundingClientRect().left)x=event.srcElement.getBoundingClientRect().left
                if(x>event.srcElement.getBoundingClientRect().left+event.srcElement.offsetWidth-offsetWidth)x=event.srcElement.getBoundingClientRect().left+event.srcElement.offsetWidth-offsetWidth
                style.posLeft=x
                parentNode.style["display"]="block";
        }
 
}  
                   
                      
function fileAttachmentclick1(obj)
{
     with(obj)
     {
        style.posTop=event.srcElement.getBoundingClientRect().top
         var x=event.x-offsetWidth/2
         if(x<event.srcElement.getBoundingClientRect().left)x=event.srcElement.getBoundingClientRect().left
        if(x>event.srcElement.getBoundingClientRect().left+event.srcElement.offsetWidth-offsetWidth)x=event.srcElement.getBoundingClientRect().left+event.srcElement.offsetWidth-offsetWidth
        style.posLeft=x
    }
}  
        </script>

    </form>
</body>
</html>

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Webb.WAVE.Controls.Upload;
using System.IO;
namespace GloryView.Meeting.Web.Module.admin.MeetingManage
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnUpLoad_Load(object sender, EventArgs e)
        {

            Button m_button = sender as Button;
            WebbUpload m_upload = new WebbUpload();
            m_upload.RegisterProgressBar(m_button);
         

        }

        private void UploadFiles(string meetingID)
        {
 
            string m_path = Path.Combine(MapPath("~"), "MeetingAffix""" + DateTime.Now.Year.ToString() + """" + DateTime.Now.Month.ToString() + """" + meetingID);
            //Response.Write(m_path);
            WebbUpload m_upload = new WebbUpload();
            UploadFileCollection m_files = m_upload.GetUploadFileList("files");
            string m_filePath = string.Empty;

          //  this.Label1.Text = "Uploaded file:<br/>";
            foreach (UploadFile m_file in m_files)
            {
                //每上传成功一个文件就插入数据库一个跳记录
                //如果失败,则退出,提示用户上传文件失败,让用户就如修改界面进行重新上传文件
                if (m_file.FileName == null || m_file.FileName == string.Empty) continue;    //skip the empty input file.
                m_filePath = Path.Combine(m_path, m_file.FileName);
                m_file.SaveAs(m_filePath);
              //  this.Label1.Text += "<a href='""uploadedFiles""" + m_file.FileName + "'>uploadedFiles""" + Path.GetFileName(m_file.ClientFullPathName) + "</a><p>";
            }

            m_files = m_upload.GetUploadFileList("saomiaoFile");
            m_filePath = string.Empty;

            //this.Label2.Text = "Uploaded file:<br/>";
            foreach (UploadFile m_file in m_files)
            {
                if (m_file.FileName == null || m_file.FileName == string.Empty) continue;    //skip the empty input file.
                m_filePath = Path.Combine(m_path, m_file.FileName);
                m_file.SaveAs(m_filePath);
                //this.Label2.Text += "<a href='""uploadedFiles""" + m_file.FileName + "'>uploadedFiles""" + Path.GetFileName(m_file.ClientFullPathName) + "</a><p>";
            }
        }

        protected void btnUpLoad_Click(object sender, EventArgs e)
        {
            UploadFiles(Guid.NewGuid().ToString());
        }

    }
}

使用了博客园中的开源的大文件上传组件,没有完全调同,可是总体思路已经差不多了,有时间完善他。
现在系统的第一个版本用了一个比126信箱简单多的方法,可是也能搞定问题了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值