求文件上传代码(vs2003的)我写的老出错。
谢谢。

解决方案 »

  1.   

    <html>
    <title>文件上传</title><body>
    <form enctype="multipart/form-data" runat=server>
    <Input type=file id=fileup runat=server size="20"><p>
    <asp:button id=upload_button onclick=uploadfile text="上传" runat=server/>
    </form>
    <p>
    <asp:label id=uptype runat=server/>
    </body>
    </html>
    <script language=VB runat=server>
    Sub uploadfile(sender as object,e as eventargs)
    If fileup.postedfile.contentlength=0 Then
    uptype.text="你还没有选择需要上传的文件!"
    Else
    Dim filesplit() as string=split(fileup.postedfile.filename,"\")
    Dim filename as string=filesplit(filesplit.length-1)
    fileup.postedfile.saveas(server.mappath(".")&"\"&filename)
    uptype.text="文件名称:"&fileup.postedfile.filename &"<br>"& _
    "文件大小:"&fileup.postedfile.contenttype &"<br>"& _
    "文件类型:"&fileup.postedfile.contentlength
    End IfEnd Sub
    </script>
      

  2.   

    小文件上传//产生新文件名
    string newFileName = ToniRoot.uploadFile.newFileName(ToniRoot.uploadFile.getExtName(ToniRoot.uploadFile.getFileName(File1.PostedFile.FileName)));
    //产生新路径
    System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
    string PhotoPath = ((string)(configurationAppSettings.GetValue("PhotoPath", typeof(string))));
    string newFilePath = ToniRoot.uploadFile.newFilePath(PhotoPath,newFileName);
    //验证新路径
    if (!Directory.Exists(Server.MapPath(newFilePath)))
    {
         Directory.CreateDirectory(Server.MapPath(newFilePath));
    }
    //保存文件
    File1.PostedFile.SaveAs(Server.MapPath(newFilePath+newFileName));//File1是protected System.Web.UI.HtmlControls.HtmlInputFile File1; htmlInputfile组件
    如果上传大文件请用一些文件上传组件如neatupload