Simple ImageShack upload using C#
Filed Under (c#) by The Chef on 08-06-2009
Tagged Under : c#, ImageShack, ImageShack API, memory xml deserialize
First of all this class is based on the http helper class. The rest is trivial. Here is a piece of code
public static class ImageShack
{
private static http http = new http();
public static String UploadImage(String filename)
{
http.PostMode = PostMode.Multipart;
http.AddPostKey("xml", "yes");
http.AddPostFile("fileupload", filename);
return http.GetUrl("http://www.imageshack.us/index.php");
}
}
The result is an xml. You can deserialize it using the XML serializer/deserializer from the previous post.
[Serializable]
public class links
{
public String image_link;
public String thumb_link;
public String ad_link;
public String thumb_exists;
public int total_raters;
public float ave_rating;
public String server;
public String image_name;
public String done_page;
public String resolution;
public int filesize;
public String image_class;
}
.
.
.
imageshark isr=new imageshark();
links lnk = new links();
lnk = XMLData.ObjectXMLSerializer<links>.LoadString(ImageShack.UploadImage("picture.png"));
Console.WriteLine(lnk.image_link);
Hope it helps. Enjoy