Groups > Asp .Net > ASP.NET components > Re: please i need quick help




Re: please i need quick help

Re: please i need quick help
Wed, 19 Mar 2008 16:49:37 +000
The line 35 must to change to result = result.Substring(0,
result.IndexOf("</div"));. You has wroten ">/div". The
correct is "</div".
Post Reply
Re: please i need quick help
Wed, 19 Mar 2008 16:59:17 +000
thanks

the same error occures

if i delete this line it gives me 

"google

fobidden"

any other suggestion?
Post Reply
Re: please i need quick help
Wed, 19 Mar 2008 17:47:06 +000
i'm trying to use it like this but i doesn't work

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Net;

publicpartialclassadmin_Default : System.Web.UI.Page

{protectedvoid Page_Load(object sender, EventArgs e)

{if (!Page.IsPostBack)

{

user.InnerText = User.Identity.Name;

}

}protectedvoid Button1_Click(object sender, EventArgs e)

{r1.InnerHtml = TranslateText(t1.Text, "ar|eg");

}publicstring TranslateText(string input, string languagePair)

{

try

{string url =
String.Format("http://www.google.com/translate_t?hl&text=&langpa
ir=", input, languagePair);

Uri uri = newUri(url);System.Net.WebClient webCliente = new
System.Net.WebClient();

 

//Set the system proxy with valid server address or IP and port. object pry =
new System.Net.WebProxy(uri);

//The DefaultCredentials automically get username and password. pry.Credentials
= CredentialCache.DefaultCredentials;

GlobalProxySelection.Select = pry;System.IO.Stream DatosRegresados =
webCliente.OpenRead(url);

string result = DatosRegresados.ToString;result =
result.Substring(result.IndexOf("id=result_box") + 22,
result.IndexOf("id=result_box") + 500);

result = result.Substring(0, result.IndexOf("</div"));return
result;

}catch (Exception ex)

{

Interaction.MsgBox(ex.Message, MsgBoxStyle.Exclamation);

}

} 

 

 

}

it gives me  the following error

Description: An error occurred during the compilation of a resource required to
service this request. Please review the following specific error details and
modify your source code appropriately. 

Compiler Error Message: CS1061: 'object' does not contain a definition for
'Credentials' and no extension method 'Credentials' accepting a first argument
of type 'object' could be found (are you missing a using directive or an
assembly reference?)

Source Error:



Line 45:             //The DefaultCredentials automically get username and
password. 
Line 46: 
Line 47:             pry.Credentials = CredentialCache.DefaultCredentials;
Line 48: 
Line 49:             GlobalProxySelection.Select = pry;
Post Reply
please i need quick help
Wed, 19 Mar 2008 18:39:48 +000
hi,

i have a problem in using google translator 

my code is like this

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using System.Net;

publicpartialclassadmin_Default : System.Web.UI.Page

{protectedvoid Page_Load(object sender, EventArgs e)

{if (!Page.IsPostBack)

{

user.InnerText = User.Identity.Name;

}

}protectedvoid Button1_Click(object sender, EventArgs e)

{r1.InnerHtml = ArEgTranslate(t1.Text, "ar|eg");

}publicstring ArEgTranslate(string input, string languagePair)

{string url =
String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text
=&langpair=", input, languagePair);

WebClient webClient = newWebClient();webClient.Encoding =
System.Text.Encoding.GetEncoding("UTF-8");

string result = webClient.DownloadString(url);result =
result.Substring(result.IndexOf("id=result_box") + 22,
result.IndexOf("id=result_box") + 500);

result = result.Substring(0, result.IndexOf(">/div"));return
result;

}

}

and i got the followin error when i run the application

 

Description: An unhandled exception occurred during the execution of the current
web request. Please review the stack trace for more information about the error
and where it originated in the code. 

Exception Details: System.ArgumentOutOfRangeException: Length cannot be less
than zero.
Parameter name: length

Source Error:



Line 33:         string result = webClient.DownloadString(url);
Line 34:         result =
result.Substring(result.IndexOf("id=result_box") + 22,
result.IndexOf("id=result_box") + 500);
Line 35:         result = result.Substring(0,
result.IndexOf(">/div"));
Line 36:         return result;
Line 37: 
 

please i need a help
Post Reply
Re: please i need quick help
Thu, 20 Mar 2008 12:15:50 +000
The type of "prx" is object. Object type not contains a
"Credentials" property. To do that, you must to change the line
below:

object pry = new System.Net.WebProxy(uri);

To

System.Net.WebProxy pry = new System.Net.WebProxy(uri);
Post Reply
about | contact