Results 1 to 3 of 3

Thread: Saving Files from a WebServer

  1. #1

    Thread Starter
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52

    Saving Files from a WebServer

    I know how to get a System.IO.Stream of the file i need from my webserver, but what I'm a little lost on is how do I then take that stream and save it to a file? I actually need to save it over a file that already exists on the local hard drive.

    I haven't uses IO stuff much, so I'm a bit lost
    -Erik Porter
    .NET MVP

  2. #2
    Registered User
    Join Date
    Nov 2002
    Location
    Växjö, Sweden
    Posts
    314
    Create a StreamReader (maybe BinareReader) to read from your stream and then use a StreamWrter (maybe BinaryWriter) to write to a FileStream object. Something like this (you didn't have a filestream as source, but that shouldn't matter).....

    Code:
    Dim fsr As New System.IO.FileStream("D:\savedPic.gif", IO.FileMode.Open)
    Dim fsw As New System.IO.FileStream("D:\pic2.gif", IO.FileMode.Create)
    Dim br As New System.IO.BinaryReader(fsr)
    Dim bw As New System.IO.BinaryWriter(fsw)
    bw.Write(br.Read)

  3. #3

    Thread Starter
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52
    cool, thanx, i'll give that a go!

    i was trying sort of the same thing, but longer (looping through each byte and writing it to the new stream), but if your way works, it's a lot shorter and i'll use that
    -Erik Porter
    .NET MVP

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