<%@ Page Language="C#" %>
<%@ import Namespace="System.Text" %>
<script runat="server">

    // Insert page code here

    void Upload_Click(object sender, EventArgs e)
{
    int arcid=int.Parse(Request.QueryString["id"]);
    HttpFileCollection files=Request.Files;
    StringBuilder strMsg=new StringBuilder("上传文档信息:<br>");
    int ifile;
    try
    {
     for(ifile=0;ifile<files.Count;ifile++)
     {
      HttpPostedFile postedFile=files[ifile];
      string filename,fileextension;
      filename=System.IO.Path.GetFileName(postedFile.FileName);
      if(filename!="")
      {
       fileextension=System.IO.Path.GetExtension(filename);
       strMsg.Append("上传文件类型:"+postedFile.ContentType.ToString()+"<br>");
       strMsg.Append("本地文件路径:"+postedFile.FileName+"<br>");
       strMsg.Append("上传文件名称:"+filename+"<br>");
      
       postedFile.SaveAs(Server.MapPath("../uploadfiles/") + filename);
       string fileurl="uploadfiles/"+filename;
      
       
      }

     }
     Label1.Text=strMsg.ToString();
    }
    catch
    {
     Label1.Text="fail";
    }

    }

  </script>
<html>
<head>
    <script language="JavaScript">
    function addFile()
    {
     var str = '<INPUT type="file" size="50px" NAME="File"><br>'
     document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str)
    }
    </script>
    <link href="images/style.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <form id="form1" method="post" enctype="multipart/form-data" runat="server">
        <!-- Insert content here -->
        <div class="mframe">
            <table cellspacing="0" cellpadding="0" width="640" align="center">
                <tbody>
                    <tr>
                        <td class="tl">
                        </td>
                        <td class="tm">
                            <table width="100%">
                                <tbody>
                                    <tr>
                                        <td>
                                            <span class="tt">上传文档</span></td>
                                        <td align="right">
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                        <td class="tr">
                        </td>
                    </tr>
                </tbody>
            </table>
            <table cellspacing="0" cellpadding="0" width="640" align="center">
                <tbody>
                    <tr>
                        <td class="ml">
                        </td>
                        <td class="mm">
                            <table cellspacing="0" cellpadding="3" width="95%" align="center">
                                <tbody>
                                     <tr>
                                        <td valign="top" width="15%">
                                            上传文档:</td>
                                        <td>
                                            <p align="center">
                                            </p>
                                            <p id="MyFile">
                                                <input type="file" size="50px" name="File" />
                                                <br />
                                            </p>
                                            <p>
                                            </p>
                                            <p>
                                                <asp:Label id="Label1" runat="server"></asp:Label>
                                            </p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="tdbg-dark" align="middle" colspan="2">
                                            <input onclick="addFile()" type="button" value="增加(Add)" />
                                            <asp:Button id="Upload" onclick="Upload_Click" Text="上传" Runat="server"></asp:Button>
                                            <input onclick="this.form.reset()" type="button" value="重置(ReSet)" />
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                        <td class="mr">
                        </td>
                    </tr>
                </tbody>
            </table>
            <table cellspacing="0" cellpadding="0" width="640" align="center">
                <tbody>
                    <tr>
                        <td class="bl">
                        </td>
                        <td class="bm">
                            &nbsp;</td>
                        <td class="br">
                        </td>
                    </tr>
                </tbody>
            </table>
            <!-- Insert content here -->
        </div>
    </form>
</body>
</html>

posted on 2006-04-18 00:41  kirk.net  阅读(811)  评论(1)    收藏  举报
free web counter
free web counter