如题,谢谢大家啊,我新手详细点谢谢呀

解决方案 »

  1.   

    <%@ page Language="C#" debug="true"  codepage="936"%>
    <%@ Import Namespace="System.IO" %>
    <HTML>
    <HEAD>
    <title>文件上传,aspcool.com </title>
    <%--
    upload.aspx
    这是一个上传文件,从中我们可以看出asp.net的优势,以前需要控件才能完成的程序,现在只需要几行代码就可以轻松完成。
    --%>
    <script language="C#" runat="server">
        
                public void UploadFile(object sender , EventArgs E)
                {
           
                    if(myFile.PostedFile!=null)
                    {
                        //定义一些变量
                        string nam = myFile.PostedFile.FileName ;
                        int i= nam.LastIndexOf("\\") ;
                        string newnm =nam.Substring(i) ;                    
                        //改变下面的“c:\\"到你想要保存的地址。
                        myFile.PostedFile.SaveAs("c:\\"+newnm) ;                    //取得上传文件的各种属性。
                        fname.Text=myFile.PostedFile.FileName;
                        fenc.Text=myFile.PostedFile.ContentType ;
                        fsize.Text=myFile.PostedFile.ContentLength.ToString();
                    }
                } </script>
    </HEAD>
    <body ms_positioning="GridLayout">
    <TABLE height="410" cellSpacing="0" cellPadding="0" width="800" border="0" ms_2d_layout="TRUE">
    <TR vAlign="top">
    <TD width="10" height="15"></TD>
    <TD width="790"></TD>
    </TR>
    <TR vAlign="top">
    <TD height="395"></TD>
    <TD>
    <center>
    <h3>文件上传演示
    </h3>
    <form id="uploderform" action="upload.aspx" method="post" encType="multipart/form-data"
    runat="server">
    <TABLE height="146" cellSpacing="0" cellPadding="0" width="521" border="0" ms_2d_layout="TRUE">
    <TR vAlign="top">
    <TD width="278" height="146"></TD>
    <TD width="243">
    <table cellSpacing="0" cellPadding="0" border="1" height="90" width="232">
    <tr>
    <td>
    <h5>选择文件</h5>
    </td>
    </tr>
    <tr>
    <td><input id="myFile" type="file" name="myFile" runat="server">
    </td>
    </tr>
    <tr>
    <td><input id="Button1" type="button" value="Upload" name="Button1" runat="server" OnServerClick="UploadFile">
    </td>
    </tr>
    </table>
    </TD>
    </TR>
    </TABLE>
    </form>
    <br>
    <br>
    <table cellSpacing="0" border="1">
    <tr>
    <td><b>文件资料</b></td>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>文件名称 :</td>
    <td><asp:label id="fname" runat="server" text=""></asp:label></td>
    </tr>
    <tr>
    <td>文件类型 :</td>
    <td><asp:label id="fenc" runat="server"></asp:label></td>
    </tr>
    <tr>
    <td>文件大小 :(in bytes)</td>
    <td><asp:label id="fsize" runat="server"></asp:label></td>
    </tr>
    </table>
    <asp:Label id="message" runat="server"></asp:Label>
    <br>
    <br>
    <br>
    </center>
    </TD>
    </TR>
    </TABLE>
    </body>
    </HTML>
    代码复制就可运行.
      

  2.   

    myFile.PostedFile.SaveAs(strFileName) ;  
    myFile是System.Web.UI.HtmlControls.HtmlInputFile 控件
    iis用户必须有权限操作那个目录
      

  3.   

    protected System.Web.UI.HtmlControls.HtmlInputFile d_uploadfile;
    public void UpLoadFileToServer()
    {
    if (d_checkfromfile.Checked)
    {
    string UploadFileName = "";
    string UploadFileDestination = "";
    UploadFileName = d_uploadfile.PostedFile.FileName;
    UploadFileName = DateTime.Now.ToString("yyMMddhhmm")+"_"+UploadFileName.Replace(" ","").Substring(UploadFileName.LastIndexOf("\\") +1);
    UploadFileDestination = HttpContext.Current.Request.PhysicalApplicationPath;
    UploadFileDestination += "Admin\\upload\\";
    UploadFileDestination += UploadFileName;
    d_uploadfile.PostedFile.SaveAs(UploadFileDestination); }
    }