Click here to Skip to main content
15,883,901 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionUnable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream' Pin
silentspeaker8-Nov-12 1:55
silentspeaker8-Nov-12 1:55 
Hi,
I want to upload browsed file to the ftp server but getting this error


 Sub UploadFile()

        Try
            Dim fileName As String = FulFile.PostedFile.FileName
            Dim requestFTP As WebRequest = WebRequest.Create("ftp://...................." & fileName)
            requestFTP.Credentials = New NetworkCredential("userid", "password")
            requestFTP.Method = WebRequestMethods.Ftp.UploadFile


            Dim fStream As FileStream = FulFile.PostedFile.InputStream 'Error:Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream'.


            Dim bufferLength As Integer = 2048
            Dim buffer As Byte() = New Byte(bufferLength - 1) {}

            Dim uploadStream As Stream = requestFTP.GetRequestStream()
            Dim contentLength As Integer = fStream.Read(buffer, 0, bufferLength)

            While contentLength <> 0
                uploadStream.Write(buffer, 0, contentLength)
                contentLength = fStream.Read(buffer, 0, bufferLength)
            End While
            uploadStream.Close()
            fStream.Close()
            requestFTP = Nothing

            LblMsg.Text = "File Uploading Is SuccessFull..."

        Catch ep As Exception
            LblMsg.Text = ep.Message
        End Try

    End Sub

AnswerRe: Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream' Pin
Richard Deeming8-Nov-12 2:26
mveRichard Deeming8-Nov-12 2:26 
GeneralRe: Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream' Pin
silentspeaker8-Nov-12 2:34
silentspeaker8-Nov-12 2:34 
GeneralRe: Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream' Pin
Richard Deeming8-Nov-12 2:44
mveRichard Deeming8-Nov-12 2:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.