Results 1 to 6 of 6

Thread: Writing FileStream to Disc [Resolved]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belfast, N. Ireland
    Posts
    167

    Writing FileStream to Disc [Resolved]

    Hello,

    This is probably a simple enough question.

    I want to transfer a file from a server computer to a client using remoting. Which type should I use for the file in the remotable class? I'm comfortable with remoting, however I'm not entirely familiar with FileStreams etc.

    Should I even use a FileStream, or should I pass the file as a string? How do I write a FileStream to disc?

    Thanks in advance for your help, I haven't had much luck trying to work this out myself.

    Justin.

    Last edited by Justy; Nov 20th, 2003 at 12:05 PM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belfast, N. Ireland
    Posts
    167
    Well then can anyone give me some advice on this code?

    VB Code:
    1. Public Function Download() As FileStream        
    2.         Return New FileStream("C:\Test.bmp", FileMode.Open, FileAccess.Read)
    3. End Function
    4.  
    5. Public Sub Run
    6.         Dim fileContent As Byte()
    7.         Dim MyStream As FileStream = Download()
    8.  
    9.         MyStream.Read(fileContent, 0, Integer.MaxValue)
    10.         MyStream.Close()
    11.  
    12.         MyStream = New FileStream("C:\TEST2.BMP", FileMode.Create, FileAccess.Write)
    13.         MyStream.Write(fileContent, 0, fileContent.Length)
    14.         MyStream.Close()
    15. End Sub

    The Download() function will normally be a remotable class, but I've simplified things above. When the Run() method is called, I get the following error

    Code:
    System.ArgumentNullException
    Additional information: Buffer cannot be null
    Or if anyone has any examples of transferring files using remoting then please let me know. Thanks...

    Justin.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belfast, N. Ireland
    Posts
    167
    Where have all the experts gone?


  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Originally posted by Justy
    Where have all the experts gone?

    I think they have the day off.

    Also it would be helpful to know which line of code gives that error and try flushing before you close.

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Well the reason for the error is because you have not explicitly set the Byte array size. You must get the length of the stream and set the byte array length to it when you declare the array, before reading the stream into it.

    VB Code:
    1. Dim MyStream As FileStream = Download()
    2.  
    3. Dim fileContent(MyStream.Length) As Byte
    4.  
    5.   MyStream.Read(fileContent, 0, Integer.MaxValue)
    Last edited by nemaroller; Nov 20th, 2003 at 11:20 AM.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Belfast, N. Ireland
    Posts
    167
    Thankyou nemaroller.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width