0

I'm using VB .Net for Windows Phone 8. I'm trying to get first line from txt file. Txt file is located in Web.

Dim path As String
path="http://web.com/text.txt"

Using TXT As New StreamReader(path)
    TextBox1.Text = TXT.ReadLine()
End Using

And I get Error Message in this line Using TXT As New StreamReader(path)

Value of type 'String' cannot be converted to 'System.IO.Stream'

How can I set path to the file without using of String variable?

Vivek S.
  • 19,945
  • 7
  • 68
  • 85
Artur Tychina
  • 105
  • 2
  • 8
  • 1
    Use a WebRequest if you want to read from an url. – Tim Schmelter Aug 19 '14 at 10:21
  • I agree with Tim. If you want to be fancy, Make a web service that does this for you and only return a value.. Remember that you must have as little code on the device as possible, this makes your app faster.. – Jonny Aug 19 '14 at 10:28
  • Is the code complete? The typing seems to be OK unless you omitted something. – Robert Aug 19 '14 at 11:03

3 Answers3

0

Using simply txt.ReadToEnd to read all string that's all

makemoney2010
  • 1,222
  • 10
  • 11
  • I get an error before i can use txt.ReadToEnd. I get it here: Using TXT As New StreamReader(path) – Artur Tychina Aug 19 '14 at 10:27
  • Sorry Arthur i was a little bit busy, you're issue(and i see it now) it that you're trying toread from an url.you need to download the file into your computer or using an httpwebrequest read the stream and the update the control.You cannot do it before – makemoney2010 Sep 24 '14 at 08:03
  • I have used this one: Dim httpClient As HttpClient = New HttpClient() Dim form As New MultipartFormDataContent() Dim response As HttpResponseMessage = Await httpClient.PostAsync(getUrl, form) responseText = Await response.Content.ReadAsStringAsync() – Artur Tychina Sep 25 '14 at 10:58
0

You should use HttpWebRequest to get stuff back from a URL, so something like this...

Imports System.Net

then

Dim wRequest As HttpWebRequest = HttpWebRequest.Create("http://www.bbc.co.uk/news")

wRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
wRequest.Accept = "application/text"
wRequest.Method = "GET"

Dim wResponse As HttpWebResponse = DirectCast(wRequest.GetResponse(), HttpWebResponse)

Using srRead As New StreamReader(wResponse.GetResponseStream())
    Dim sResponse As String = srRead.ReadToEnd()
End Using
Ciarán
  • 3,017
  • 1
  • 16
  • 20
  • I get error message for this string of your code: Dim wResponse As HttpWebResponse = wRequest.GetResponse(); Error is: 'GetResponse' is not a member of 'System.Net.HttpWebRequest' – Artur Tychina Aug 19 '14 at 13:34
  • Really? It works just fine here. What version of .Net are you using? You may need to include a reference to System.Net, though I haven't. Try a DirectCast (see above) – Ciarán Aug 19 '14 at 13:52
  • System.Net is Imported and DirectCast doesn't help. I'm using Microsoft Visual Studio 12.0 and NET.Framework 4.5 – Artur Tychina Aug 19 '14 at 14:03
  • No, not an Imports a **Reference**. I'll try it in VS2012 and 4.5. Hang on. – Ciarán Aug 19 '14 at 14:15
  • I've tried it in VS2012 and 4.5 and it works just fine. Take the code snippet out into a console app and see if that runs. If so then you may have a conflict somewhere. – Ciarán Aug 19 '14 at 14:22
  • I have not VS2012, but VS2013 version 12.0; Microsoft Visual Studio Professional 2013 Version 12.0.30501.00 Update 2 Microsoft .NET Framework Version 4.5.51641 – Artur Tychina Aug 19 '14 at 14:28
  • Don't have that I'm afraid, maybe someone else can help. This works just fine in VS2008 and VS2012. Sorry. – Ciarán Aug 19 '14 at 14:36
0
Dim httpClient As HttpClient = New HttpClient()
Dim form As New MultipartFormDataContent()
Dim getUrl As String = "http://website/test.txt"
            Dim response As HttpResponseMessage = Await httpClient.PostAsync(getUrl, form)
            responseText = Await response.Content.ReadAsStringAsync()

This one is working well

Artur Tychina
  • 105
  • 2
  • 8