|
-
Nov 18th, 2003, 11:56 AM
#1
Thread Starter
Addicted Member
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.
-
Nov 19th, 2003, 10:28 AM
#2
Thread Starter
Addicted Member
Well then can anyone give me some advice on this code?
VB Code:
Public Function Download() As FileStream
Return New FileStream("C:\Test.bmp", FileMode.Open, FileAccess.Read)
End Function
Public Sub Run
Dim fileContent As Byte()
Dim MyStream As FileStream = Download()
MyStream.Read(fileContent, 0, Integer.MaxValue)
MyStream.Close()
MyStream = New FileStream("C:\TEST2.BMP", FileMode.Create, FileAccess.Write)
MyStream.Write(fileContent, 0, fileContent.Length)
MyStream.Close()
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.
-
Nov 20th, 2003, 09:30 AM
#3
Thread Starter
Addicted Member
Where have all the experts gone?
-
Nov 20th, 2003, 11:07 AM
#4
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.
-
Nov 20th, 2003, 11:14 AM
#5
I wonder how many charact
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:
Dim MyStream As FileStream = Download()
Dim fileContent(MyStream.Length) As Byte
MyStream.Read(fileContent, 0, Integer.MaxValue)
Last edited by nemaroller; Nov 20th, 2003 at 11:20 AM.
-
Nov 20th, 2003, 12:04 PM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|