Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

ImageShack and Shell programing

  1. Aug 7, 2008 #1
    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.

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

    Code (Text):
    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\*\shell\Open with Notepad]

    [HKEY_CLASSES_ROOT\*\shell\Open with Notepad\command]
    @="notepad.exe %1"
    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. jcsd
  3. Aug 13, 2008 #2
    ImageShack has an API:

    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
  4. Aug 13, 2008 #3
    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 :cry:

    they say

    my code:
    Code (Text):

    string fileName = "C:\\Documents and Settings\\Harmeet Cheema\\My Documents\\My Pictures\\Avril.JPG";
    StreamReader streamRdr = new StreamReader(fileName);
                String file = streamRdr.ReadToEnd();
                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);
                //Get the response handle, we have no true response yet!
                HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
                //Let's show some information about the response
    Last edited by a moderator: May 3, 2017
  5. Aug 13, 2008 #4
    But, using dirty solution. Make direct post to their page, I managed to get the file address..

    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
  6. Aug 13, 2008 #5
    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

            function uploadToImageshack($filename) {

                    //Connect to imageshack
                    $ch = curl_init("http://www.imageshack.us/index.php");
                    //$_POST data

                    //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);

                    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
  7. Aug 13, 2008 #6
    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
  8. Aug 14, 2008 #7
    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.

  9. Aug 14, 2008 #8
    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 ..)
  10. Aug 14, 2008 #9
    Thanks guys!
    I am done :biggrin:

    http://img237.imageshack.us/img237/2569/screen1rc1.png [Broken]
    Select the file
    http://img519.imageshack.us/img519/7682/screen2uv9.png [Broken]
    Click on the upload button
    http://img237.imageshack.us/img237/8623/screen3tp1.png [Broken]
    It anagrammatically copies to the clipboard!
    Last edited by a moderator: May 3, 2017
  11. Aug 14, 2008 #10
    And, it's possible to upload multiple files and all images in a directory.
    Last edited by a moderator: May 3, 2017
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: ImageShack and Shell programing
  1. Unix Shell Script (Replies: 3)