ASP.NET/VB.NET FileUpload Control

后端 未结 2 730
情深已故
情深已故 2021-01-21 23:15

I have a problem with FileUpload, when I select a file from the local machine, it will not bring the real path of the file, it will use the path for the project files and assume

相关标签:
2条回答
  • 2021-01-21 23:32

    The problem is you're trying to read in the PostedFile as a local file (on the web server), not from the HttpPostedFile object attached to the FileUploader.

    Try:

    Dim objFileStream As System.IO.Stream = FU.PostedFile.InputStream
    Dim bFile(objFileStream.Length) As Byte
    objFileStream.Read(bFile, 0, objFileStream.Length)
    
    0 讨论(0)
  • 2021-01-21 23:52

    I tried something, and it worked..

                FU.SaveAs("C:\" & FU.FileName)
    
                '--------------------------
                ' set up request...
    
                Dim LocFile As String = FU.PostedFile.FileName
                Dim clsRequest As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("MyFTP.com" & LocFile), System.Net.FtpWebRequest)
    
                clsRequest.Credentials = New System.Net.NetworkCredential("username", "password")
                clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
    

    It worked.. simply saved the file from FU (FileUpload) to C:\ and then setting the address to always start at C:\

    0 讨论(0)
提交回复
热议问题