1

I have a simple code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;

public partial class WebClient : PhoneApplicationPage
{
    public WebClient()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        WebClient webclient = new WebClient();

Now when I say webClient., I expected to see DownloadStringCompleted in the IntelliSense dropdown but I dont see. And when I force use it, ofcourse it doesn't compile. What is the problem?

I am testing WebClient to see if it is of use in my project since I am fed up with the async calls and multiple threads associated with HttpWebRequest

Ravi
  • 147
  • 1
  • 10
  • What is the compile error you see? Is System.Net in the set of assemblies referenced by your project? Do you see any other methods in the Intellisense dropdown? – indyfromoz Jan 16 '11 at 00:15

3 Answers3

5

You have for some strange reason used the name "WebClient" as the class name for your PhoneApplicationPage. Hence when you use this line:-

 WebClient webclient = new WebClient();

It attempts to create another instance of your page which of course does not have a DownloadStringCompleted or anything else provided by the WebClient in the System.Net namespace.

I would strongly suggest you give your page a different name. If you really did want to call your page "WebClient" then how about "WebClientPage"?

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • Awesome and aweful ... Awesome you could point the mistake accurately. Aweful me for doing such a silly mistake – Ravi Jan 17 '11 at 07:44
1

Seems to work ok here.

I opened the projected posted here.

WebClient, HttpWebRequest and the UI Thread on Windows Phone 7

Changed the WebClient usage to this

    webClient.DownloadStringAsync(new Uri("http://www.bing.com"));
    webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);

and wrote the new event handler as

void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) {
    System.Diagnostics.Debug.WriteLine("e.Error: " + e.Error);
    webClientTextBlock.Text = e.Result;
}

Worked just the same as before except I'm pulling a string down through e.Result instead of a stream.

Mick N
  • 14,892
  • 2
  • 35
  • 41
1

You need to see the referrenced assemblies. Add the assemblies related to WP7 to see intellisense working properly.

Thanigainathan
  • 1,505
  • 14
  • 25