ImageShack and Shell programing

1. Aug 7, 2008

rootX

I am creating a product (for personal use)
when I left click an image, "Upload to ImageShack" should show up
and when I click that I want to upload the file to image shack and provide me the uploaded file address in dialog box/other ways

Currently, I am working on .Net web application. I copied all java script from image shack and put it under my project. It is almost done (few problems)

Then, I am thinking of making an .exe file that would start this web application or it might talk to imageshack directly.
http://imageshack.us/

And, that "Upload to ImageShack" should start the .exe program.

Code (Text):
Windows Registry Editor Version 5.00

This opens up notepad, and I want to make similar that opens my program and provide file location as a parameter.

Any help would be appreciated!

This is my second personal project. In the first one, I created excel 2007 add-in that emails my files to gmail account when I click a button (I really wanted it for backing up my data and remote use)
If there's a better way to achieve the final functioning?

Last edited: Aug 7, 2008
2. Aug 13, 2008

dashed

ImageShack has an API:
http://reg.imageshack.us/content.php?page=developer

Using the XML API provided should be easy to integrate.

Refer to php code: http://elliottback.com/wp/archives/2008/06/01/using-the-imageshack-xml-api/ [Broken]

The code provided, should be fairly easy to modify and convert to .NET code.

Imageshack some simple examples to using their API once you have requested for a developer key. But these are geared towards web based applications.

Last edited by a moderator: May 3, 2017
3. Aug 13, 2008

rootX

Thanks that was neat!

using HttpRequest class, it's simple 20 lines code but mine didn't work. Doesn't return anything
One question: I passed file name first and then file stream .. none worked

they say

my code:
Code (Text):

string fileName = "C:\\Documents and Settings\\Harmeet Cheema\\My Documents\\My Pictures\\Avril.JPG";

byte[] buffer = Encoding.Unicode.GetBytes("fileupload=" + file + "&xml=yes");
//Initialisation, we use localhost, change if appliable
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://www.imageshack.us/index.php");
//Our method is post, otherwise the buffer (postvars) would be useless
WebReq.Method = "POST";
//We use form contentType, for the postvars.
WebReq.ContentType = "application/x-www-form-urlencoded";
//The length of the buffer (postvars) is used as contentlength.
WebReq.ContentLength = buffer.Length;
//We open a stream for writing the postvars
Stream PostData = WebReq.GetRequestStream();
//Now we write, and afterwards, we close. Closing is always important!
PostData.Write(buffer, 0, buffer.Length);
PostData.Close();
//Get the response handle, we have no true response yet!
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
//Let's show some information about the response
Console.WriteLine(WebResp.StatusCode);
Console.WriteLine(WebResp.Server);

Last edited by a moderator: May 3, 2017
4. Aug 13, 2008

rootX

But, using dirty solution. Make direct post to their page, I managed to get the file address..

Now,
I have a .EXE console application that would return the photo uploaded http address when you pass the file address to it from args.

So, I am left it putting it together with context menu

5. Aug 13, 2008

dashed

I recommend using the curl library when communicating with a web service. I don't know if .NET has native functions for this.

http://curl.haxx.se/libcurl/dotnet/ [Broken]

Their PHP example: http://reg.imageshack.us/xmlapi.zip

PHP:
function uploadToImageshack($filename) { //Connect to imageshack$ch = curl_init("http://www.imageshack.us/index.php");

//$_POST data$post['xml']='yes';
$post['fileupload']='@'.$filename;

//curl stuff
curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 240);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));$result = curl_exec($ch); curl_close($ch);

if (strpos($result, '<'.'?xml version="1.0" encoding="iso-8859-1"?>') === false) { return 'failed'; } else { return$result; // XML data
}
}
Try to convert this function into .NET code. The parameter $filename is the image store temporarily on disk to be uploaded to imageshack. The xml data should be within the variable$result.

Use a xml parser to get the information you need.

You may use a .NET xml parser (I dont know if .NET provides this function natively):
http://www.chilkatsoft.com/dotNetXml.asp [Broken]

I hope this helps.

Last edited by a moderator: May 3, 2017
6. Aug 13, 2008

rootX

Thanks, I will look further into that way.

Currently, I have one working solution, so I just want to get done the whole thing working before I start making it cleaner.

Context menu click --> open .exe and provide file location as args paramter...

Last edited by a moderator: May 3, 2017
7. Aug 14, 2008

kenewbie

Instead of a custom entry in the context menu, you can consider using "send to".

Simply make your imageshack.exe take a filename as the first parameter, then put imageshack.exe in the "documents and settings\name\send to\" folder.

Then you can right-click any file, go to "send to" and choose imageshack.

k

8. Aug 14, 2008

rootX

Thanks that was easy! Finished in 5 seconds :). I couldn't find send to in C:\doc .. so I ran "sendto" from run.

Now, I have simple application that uploads the file, returns in console and works perfectly!
Need to work on making it more user friendly .. and cleaner

I will upload my code shortly. It would be less than 100 lines (now it's about 200 ..)

9. Aug 14, 2008

rootX

Thanks guys!
I am done

http://img237.imageshack.us/img237/2569/screen1rc1.png [Broken]
Select the file
http://img519.imageshack.us/img519/7682/screen2uv9.png [Broken]