Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7088719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:50:07+00:00 2026-05-28T07:50:07+00:00

I am creating a ASP.NET (VB.NET) application that must retrieve a known remote file

  • 0

I am creating a ASP.NET (VB.NET) application that must retrieve a known remote file and return it to the visitor through their browser. I am attempting to use the sample from Microsoft located here: http://support.microsoft.com/?kbid=812406 and running into an error ‘This stream does not support seek operations’. I’m not sure how to proceed.

Here is the code with the error line marked.

Dim ftpWebReq As Net.FtpWebRequest = CType(Net.WebRequest.Create(path), Net.FtpWebRequest)
ftpWebReq.Method = Net.WebRequestMethods.Ftp.DownloadFile
ftpWebReq.KeepAlive = False
ftpWebReq.UsePassive = False
ftpWebReq.Credentials = New Net.NetworkCredential(System.Web.Configuration.WebConfigurationManager.AppSettings("FtpId"), System.Web.Configuration.WebConfigurationManager.AppSettings("FtpPwd"))
Dim ftpWebResp As Net.FtpWebResponse = CType(ftpWebReq.GetResponse(), Net.FtpWebResponse)
Dim streamer As Stream = ftpWebResp.GetResponseStream()

Dim buffer(10000) As Byte   ' Buffer to read 10K bytes in chunk:
Dim length As Integer       ' Length of the file:
Dim dataToRead As Long      ' Total bytes to read:
dataToRead = streamer.Length    ' *** This is the error line ***
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", "attachment; filename=foo.txt")
While dataToRead > 0    ' Read the bytes.
If Response.IsClientConnected Then    ' Verify that the client is connected.
   length = streamer.Read(buffer, 0, 10000) ' Read the data in buffer
   Response.OutputStream.Write(buffer, 0, length)  ' Write the data to the current output stream.
   Response.Flush()        ' Flush the data to the HTML output.
   ReDim buffer(10000) ' Clear the buffer
   dataToRead = dataToRead - length
Else
   dataToRead = -1 'prevent infinite loop if user disconnects
End If
End While
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:50:07+00:00Added an answer on May 28, 2026 at 7:50 am

    Don’t bother with dataToRead. Keep reading until length is 0 (i.e streamer.Read() has returned 0). This means you’ve reached the end of the stream.

    My VB is a bit rusty, but I think the loop should look something like this:

    finished = False
    While Not finished    ' Read the bytes.
        If Response.IsClientConnected Then    ' Verify that the client is connected.
            length = streamer.Read(buffer, 0, 10000) ' Read the data in buffer
            If length > 0 Then
                Response.OutputStream.Write(buffer, 0, length)  ' Write the data to the current output stream.
                Response.Flush()        ' Flush the data to the HTML output.
                ReDim buffer(10000) ' Clear the buffer
            Else
                finished = True
            End If
        Else
            finished = True
        End If
    End While 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an ASP.NET MVC application that has postcode lookup functionality. I capture
I'm creating an intranet asp.net mvc application that everyone in the company should have
I have created a new ActionFilter for an ASP.NET MVC application that I'm creating.
Working inside the context of an ASP.NET application I am creating a page that
I'm creating a ASP.NET MVC 2 application that envolve a section like questions here
I've got an ASP.NET application that I installed by creating a web setup. I
I'm creating an ASP.NET web application that is to communicate with a WCF web
I'm creating a text-to-speech application. it's an ASP.NET application that makes use of the
I'm creating an ASP.NET application that will log some stuff to Windows EventLog. To
I am creating an ASP.NET application that allows the user to add form elements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.