Click here to Skip to main content
       

ASP.NET

 
QuestionUnable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream' Pinmembersilentspeaker8-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' PinmemberRichard Deeming8-Nov-12 2:26 
GeneralRe: Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream' Pinmembersilentspeaker8-Nov-12 2:34 
GeneralRe: Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream' PinmemberRichard Deeming8-Nov-12 2:44 

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

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


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 10 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid