I bring a doubt. I have an interface in which I have two TextBox, one in which a long url is entered and the other in which the shortened url is shown after the button is pressed. This code in a C # Form, I would like to know how to display the short url in the TextBox.
private void btnAcortar_Click(object sender, EventArgs e)//button
{
string urlCor = txtUrlLarga.Text;
Shortener(urlCor);
}
public static string Shortener(string url)//Shortener method
{
string tinyUrl = url;
string api = "tiny url api=";
try
{
var request = WebRequest.Create(api + url);
var res = request.GetResponse();
using (var reader = new StreamReader(res.GetResponseStream()))
{
tinyUrl = reader.ReadToEnd();
}
}
catch (Exception exp)
{
Console.WriteLine(exp);
}
return tinyUrl;
}
This works on console, now I try to put it in a form.
did you try...?
private void btnAcortar_Click(object sender, EventArgs e)//button
{
string urlCor = txtUrlLarga.Text;
txtUrlShort.Text = Shortener(urlCor); //assuming your textbox is called txtUrlShort
}