Library code snippets

Interacting with TinyPic from C#

Interacting with TinyPic from C#

The following snippet will demonstrate how to interact with http://tinypic.com, an image mirroring service, directly from a C# application, using the WebRobot component available from http://foxtrot-xray.com/web-robot/

void uploadTinyPic(string imagetags, string filename){
    foxtrot.xray.WebRobot wrobot = new foxtrot.xray.WebRobot();
    foxtrot.xray.Form wform;
    foxtrot.xray.Input wtags;
    foxtrot.xray.Input wimg;
    foxtrot.xray.Input wurl;
    wrobot.Base = "http://tinypic.com/";
    wrobot.LoadPage("/");
    wform = wrobot.Forms[0];
    wtags = wform.GetFieldByName("the_tag");
    wimg = wform.GetFieldByName("the_file");
    wtags.InputValue = imagetags;
    wimg.InputValue = filename;
    wrobot.SubmitForm(wform);
    wform = wrobot.Forms[0];
    wtags = wform.GetFieldByName("mytag");
    wimg = wform.GetFieldByName("myimg");
    wurl = wform.GetFieldByName("myurl");
    System.Windows.Forms.MessageBox.Show_
("Image uploaded successfully!\r\n" +
"HTML link: " + (string)wtags.InputValue + "\r\n" +
        "[IMG] tag: " + (string)wimg.InputValue + "\r\n" +
        "Image URL: " + (string)wurl.InputValue);
}

You can download a complete project illustrating its usage here, for more convenience.

AddThis

Comments

  1. 22 Jul 2008 at 13:14

    fdbdbdbdbdbdb

Leave a comment

Sign in or Join us (it's free).

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!