Dim hpf As HttpPostedFile
fileTempName = Server.MapPath(".") & "\temp\" & uploadName
hpf.SaveAs(fileTempName)

解决方案 »

  1.   

    我是希望把表编号
    按照用户所选的选项给要上传的表编号
    我现在是用Session把用户的选项信息传过来,但不知道如何将Session里面的东西作为文件名
      

  2.   

    給你一個完整的程序,你想要得到的名字的話,你可以修改strNewName的值.
    至於你為這個文件命名,你可以參考樓上的方法.
    <%@ Import Namespace="System.IO" %>
    <%@ page Language="vb" debug="true"  codepage="936"%>
    <html><head><title>UpLoadFile_VB.aspx</title>
    <script language="vb" runat="server">
     Sub UploadFile(sender as object ,E as EventArgs)
      if not myFile.PostedFile is Nothing then
    dim PicSize as string=myFile.PostedFile.ContentLength.ToString()        dim strFileName as string =myFile.PostedFile.FileName.ToString()       
    dim namei as integer =strFileName.LastIndexOf(".") 
            dim strNameX as string=strFileName.Substring(namei)
                    'Set another file name
            dim strNewName as string =Request.UserHostAddress.ToString()+DateTime.Now.Year.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Day.ToString()+DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()+DateTime.Now.Second.ToString()+strNameX
                    
            dim strFileFolder as string =Server.MapPath("..\uploadfile_ok\1\")
            dim strNewFilePath as string =strFileFolder+strNewName
                
        myFile.PostedFile.SaveAs(strNewFilePath)
                   
    name.Text=strFileName
            fname.Text=myFile.PostedFile.FileName
            fenc.Text=myFile.PostedFile.ContentType 
            fsize.Text=myFile.PostedFile.ContentLength.ToString()
    name_cc.Text=strNameX  
    filesaveto.Text=strNewFilePath
    newfilename.Text=strNewName
      end if
    End Sub
            </script>
        </head>
    <body>
        <center>
        <h3> UpLoad Files By VB_NET_5 </h3>
        <form id="uploderform" method="post" action="uploadfile_c_5.aspx" enctype="multipart/form-data"  runat="server" >
        <table border="1" cellspacing="0" cellpadding="0" >
        <tr> <td><h5>Select File</h5></td</tr>
        <tr><td>
        <input type="file" id="myFile" runat="server" >
        </td></tr>
        <tr><td>
        <input type="button"  value="Upload" OnServerClick="UploadFile" runat="server" >
        </td></tr>
        </table>
        </form>
        <br>
        <br>
    <table border="1" cellspacing="0" width="500">
    <tr>
        <td width="200">Filename:</td>
        <td><asp:label id="name" text="" runat="server" />
    </td></tr>
    <tr>
        <td></td>
        <td><asp:label id="name_cc" text="" runat="server" />
    </td></tr>
        <tr>
        <td></td>
        <td><asp:label id="fname" text="" runat="server" />
    </td></tr>
    <tr>
        <td></td>
        <td><asp:label id="filesaveto" text="" runat="server" />
    </td></tr>
        <tr>
        <td></td>
        <td><asp:label id="fenc" runat="server" />
    </td></tr>
        <tr>
        <td></td>
        <td><asp:label id="fsize" runat="server" />
     <tr>
        <td></td>
        <td><asp:label id="newfilename" runat="server" />
    </td></tr>
    </td></tr>
        </table>
        </center>
    </body>
    </html>
      

  3.   

    loFile.PostedFile.SaveAs ( lstrFileNamePath ) 
    在这里指定