0
System.Net.WebClient wc = new System.Net.WebClient(); 

string webData = wc.DownloadString(absuri); 

After I downloaded the html from browser I am translating the text using Microsoft Translator. After that, I want to show it in the browser.

I need to replace the webRequest response data in browser, please help me here.

string txtToTranslate = TextBox1.Text;
string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text="
             + System.Web.HttpUtility.UrlEncode(txtToTranslate)
             + "&from=en&to=es";
System.Net.WebRequest translationWebRequest = System.Net.WebRequest.Create(uri);
translationWebRequest.Headers.Add("Authorization", headerValue);

System.Net.WebResponse response = null;
response = translationWebRequest.GetResponse();
System.IO.Stream stream = response.GetResponseStream();

System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
System.IO.StreamReader translatedStream = new System.IO.StreamReader(stream, encode)

System.Xml.XmlDocument xTranslation = new System.Xml.XmlDocument()
xTranslation.LoadXml(translatedStream.ReadToEnd());
string resdata = xTranslation.InnerText;

WebBrowser webBrowser = new WebBrowser();
webBrowser.DocumentStream = stream;
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
stpdevi
  • 1,114
  • 3
  • 15
  • 36
  • Possible duplicate of http://stackoverflow.com/questions/1418466/single-threaded-apartment-cannot-instantiate-activex-control – MusicLovingIndianGirl Oct 26 '15 at 08:56
  • my scenario and issue is differnt – stpdevi Oct 26 '15 at 09:00
  • what's the question? – Liam Oct 26 '15 at 09:02
  • System.Net.WebClient wc = new System.Net.WebClient(); string webData = wc.DownloadString(absuri); after downloaded the html from browser than i am translating text using microsoft translator,so here i should replace the translator text in browser...how to do it? – stpdevi Oct 26 '15 at 09:10

1 Answers1

0

The WebBrowser control you are using now is a Windows Forms or WPF control, not an ASP.NET control, which it seems you are asking for.

If you want to return anything to the browser, you have to set the response of the current HTTP context:

HttpContext.Current.Response.Write(resdata /*your desired output to the client*/);
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325