Monday, May 24, 2010

Visual C++ problem - DownloadStringAsync Result property?

I need to access the 'Result' property of 'DownloadStringAsync' so I can access the downloaded String.I have tried everything but I can't get the syntax right for accessing the Result property.The code I have written so far is shown below.When 'button 2' is clicked the web page is downloaded. It works fine so far.





private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {





Uri^ strName = gcnew Uri("http://www.yahoo.co.uk");


webClient1-%26gt; DownloadStringAsync (strName);


}





Please can you tell me what code I will have to add to this to transfer the downloaded String from the Result property to a String variable.

Visual C++ problem - DownloadStringAsync Result property?
It looks like the Result is a property of


DownloadStringCompletedEventArgs.





So you need add this as your webClient1


DownloadStringCompleted event handler:





private static void DownloadStringCallback2 (Object sender, DownloadStringCompletedEventArgs e)


{


// If the request was not canceled and did not throw


// an exception, display the resource.


if (!e.Cancelled %26amp;%26amp; e.Error == null)


{


string textString = (string)e.Result;





Console.WriteLine (textString);


}


}


No comments:

Post a Comment