My app uses a verification method for users of downloading a text file which contains game-ID's of the users and checking the file with their game-ID.

The problem is, the code I'm using to download it is kinda messing the file up.

Public Sub GetIDList()
        Dim wr As HttpWebRequest = CType(WebRequest.Create("Webserver/file"), HttpWebRequest)
        Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)
        Dim str As Stream = ws.GetResponseStream()
        Dim inBuf(100000) As Byte
        Dim bytesToRead As Integer = CInt(inBuf.Length)
        Dim bytesRead As Integer = 0
        While bytesToRead > 0
            Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)
            If n = 0 Then
                Exit While
            End If
            bytesRead += n
            bytesToRead -= n
        End While
        Dim fstr As New FileStream("C:\idlist.txt", FileMode.OpenOrCreate, FileAccess.Write)
        fstr.Write(inBuf, 0, bytesRead)
        str.Close()
        fstr.Close()
    End Sub

It downloads the file like this:

// AdminsSTEAM_0:0:16672270STEAM_0:0:23763805STEAM_0:1:13371853 STEAM_0:0:2705594STEAM_0:1:18108680STEAM_0:0:13324592STEAM_0:0:29501328STEAM_0:0:13822783STEAM_0:0:29500008STEAM_0:1:3501148// MembersSTEAM_0:1:25884948STEAM_0:0:2402602STEAM_0:1:15016054STEAM_0:1:26493339STEAM_0:0:20400113STEAM_0:0:20388510STEAM_0:0:16515880STEAM_0:0:15663660STEAM_0:0:25702968STEAM_0:1:19431130STEAM_0:0:13587742// Authorized AccessSTEAM_0:1:25703818

It's removing all the line breaks. The way the file is on the webserver is:

// Admins
STEAM_0:0:16672270
STEAM_0:0:23763805
STEAM_0:1:13371853
STEAM_0:0:2705594
STEAM_0:1:18108680
STEAM_0:0:13324592
STEAM_0:0:29501328
STEAM_0:0:13822783
STEAM_0:0:29500008
STEAM_0:1:3501148

// Members
STEAM_0:1:25884948
STEAM_0:0:2402602
STEAM_0:1:15016054
STEAM_0:1:26493339
STEAM_0:0:20400113
STEAM_0:0:20388510
STEAM_0:0:16515880
STEAM_0:0:15663660
STEAM_0:0:25702968
STEAM_0:1:19431130
STEAM_0:0:13587742

// Authorized Access
STEAM_0:1:25703818

Then I tried a different method. To streamread and write it, but that only causes this error:

URI formats are not supported.

Code for that method:

Public Shared Sub GetList()
        Try
            Using sr As StreamReader = New StreamReader("Webserver/file")
                Using sw As StreamWriter = New StreamWriter("C:\idlist.txt")

                    Dim line As String

                    Do
                        line = sr.ReadLine()
                        sw.WriteLine(line)
                    Loop Until line Is Nothing
                    sr.Close()
                    sw.Close()
                End Using
            End Using
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

I know I could simply just put spaces after each ID, but I need them to have the line breaks.

Thanks.

Try to read all bytes from the given stream.

byte[] data = new byte[ws.ContentLength];
ws.GetResponseStream().Read(data, 0, data.Length);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.