| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1158 人关注过本帖
标题:同时上传多文件问题
取消只看楼主 加入收藏
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
结帖率:100%
收藏
 问题点数:0 回复次数:3 
同时上传多文件问题
页面代码:<%@ Control Language="C#" AutoEventWireup="true" CodeFile="uploadmorefile.ascx.cs" Inherits="controls_upload" %>
 <script type="text/javascript">
    function addFileControl()
    {
        var str = '<br/><INPUT type="file" NAME="File" id="File">'
        document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str)
    }
    </script>

   
        <table width="500" border="0" cellpadding="0" cellspacing="0" align="center">
            <tr>
                <td height="25" colspan="3">
                    &nbsp;</td>
            </tr>
            <tr>
                <td height="25" colspan="3">
                    <P id="FileCollection"><INPUT type="file" name="File" id="File">
                        <asp:Label ID="Label1" runat="server" ForeColor="Red"></asp:Label></P></td>
            </tr>
            <tr>
                <td width="200" height="25">
                    <input name="button" type="button" onclick="addFileControl()" value="增加(File)"></td>
                <td width="200">
                    <asp:Button ID="Upload" runat="server" Text="上传" Width="110px" OnClick="Upload_Click">
                    </asp:Button></td>
                <td width="200">
                    <input name="button2" type="button" style="width: 56px; height: 24px" onclick="this.form.reset()"
                        value="重置"></td>
            </tr>
            <tr>
                <td height="25" colspan="3">
                    <asp:Label ID="strStatus" runat="server" BorderColor="White" BorderStyle="None" Width="500px"
                        Font-Size="9pt" Font-Bold="True" Font-Names="宋体"></asp:Label></td>
            </tr>
        </table>
  


CS代码:

 private bool upMorefile()
    {
        //遍历File表单元素
        System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
        //状态信息
        System.Text.StringBuilder strMsg = new System.Text.StringBuilder("上传的文件信息分别为:<hr color=red>");
        int fileCount;
        int filecount = files.Count;
        try
        {
            for (fileCount = 0; fileCount < files.Count; fileCount++)
            {
                //定义访问客户端上传文件的对象
                System.Web.HttpPostedFile postedFile = files[fileCount];
                string fileName, fileExtension;
                //取得上传得文件名
                fileName = (postedFile.FileName);
                if (fileName != String.Empty)
                {
                    //取得文件的扩展名
                    fileExtension = (fileName);
                    //上传的文件信息
                    strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
                    strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
                    strMsg.Append("上传文件的文件名:" + fileName + "<br>");
                    strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr color=red>");
                    //保存到指定的文件夹
                    postedFile.SaveAs(Server.MapPath("map/") + fileName);
                }
            }
            strStatus.Text = strMsg.ToString();
            return true;
        }
        catch (System.Exception error)
        {
            strStatus.Text = error.Message;
            return false;

        }
    }
    protected void Upload_Click(object sender, EventArgs e)
    {
        if (upMorefile())
        {
            Label1.Text = "上传成功";
        }
        else
        {
            Label1.Text = "上传失败";
        }

    }
搜索更多相关主题的帖子: 同时上传多文件问题 
2008-08-25 19:28
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
收藏
得分:0 
可上传不了,不知是出了什么问题

http://www.
2008-08-25 19:28
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
收藏
得分:0 
不是

http://www.
2008-08-26 11:16
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
收藏
得分:0 
还是没用,帮帮忙

http://www.
2008-08-28 11:14
快速回复:同时上传多文件问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012534 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved