10

I am sure this must have been answered before but I cannot find a solution, so I figure I am likely misunderstanding other people's solutions or trying to do something daft, but here we go.

I am writing an add-in for Outlook 2010 in C# where a user can click a button in the ribbon and submit the email contents to a web site. When they click the button the website should open in the default browser, thus allowing them to review what has just been submitted and interact with it on the website. I am able to do this using query strings in the URL using:

System.Diagnostics.Process.Start("http://www.test.com?something=value");

but the limit on the amount of data that can be submitted and the messy URLs are preventing me from following through with this approach. I would like to use an HTTP POST for this as it is obviously more suitable. However, the methods I have found for doing this do not seem to open the page up in the browser after submitting the post data:

http://msdn.microsoft.com/en-us/library/debx8sh9.aspx

to summarise; the user needs to be able to click the button in the Outlook ribbon, have the web browser open and display the contents of the email which have been submitted via POST.

EDIT:

Right, I found a way to do it, its pretty fugly but it works! Simply create a temporary .html file (that is then launched as above) containing a form with hidden fields for all the data, and have it submitted on page load with JavaScript.

I don't really like this solution as it relies on JavaScript (I have a <noscript> submit button just in case) and seems like a bit of a bodge, so I am still really hoping someone on here will come up with something better.

3 Answers 3

4

This is eight years late, but here's some code that illustrates the process pretty well:

string tempHTMLLocation = "some_arbitrary_location" + "/temp.html";
string url = https://your_desired_url.com";

    // create the temporary html file
    using (FileStream fs = new FileStream(tempHTMLLocation, FileMode.Create)) { 
        using (StreamWriter w = new StreamWriter(fs, Encoding.UTF8)) { 
            w.WriteLine("<body onload=\"goToLink()\">");
            w.WriteLine("<form id=\"form\" method=\"POST\" action=\"" + url + "\">");
            w.WriteLine("<input type=\"hidden\" name=\"post1\" value=\"" + post_data1 + "\">");
            w.WriteLine("<input type=\"hidden\" name=\"post2\" value=\"" + post_data2 + "\">");
            w.WriteLine("</form>");
            w.WriteLine("<script> function goToLink() { document.getElementById(\"form\").submit(); } </script>");
                        w.WriteLine("</body>");
        } 
    }

    // launch the temp html file
    var launchProcess = new ProcessStartInfo {
        FileName = tempHTMLLocation,
        UseShellExecute = true
    };
    Process.Start(launchProcess);

    // delete temp file but add delay so that Process has time to open file
    Task.Delay(1500).ContinueWith(t=> File.Delete(tempHTMLLocation));

Upon opening the page, the onload() JS script immediately submits the form, which posts the data to the url and opens it in the default browser.

3

The Dropbox client does it the same ways as you mentioned in your EDIT. But it also does some obfuscation, i.e. it XORs the data with the hash submitted via the URL.

Here are the steps how Dropbox does it:

  1. in-app: Create a token that can be used to authorize at dropbox.com.
  2. in-app: Convert token to hex string (A).
  3. in-app: Create a secure random hex string (B) of the same length.
  4. in-app: Calculate C = A XOr B.
  5. in-app: Create temporary HTML file with the following functionality:
  6. A hidden input field which contains value B.
  7. A submit form with hidden input fields necessary for login to dropbox.com.
  8. A JS function that reads the hash from URI, XORs it with B and writes the result to the submit forms hidden fields.
  9. Delete hash from URI.
  10. Submit form.
  11. in-app: Open the temporary HTML file with the standard browser and add C as hash to the end of the URI.

Now if your browser opens the HTML file it calculates the auth token from the hidden input field and the hash in the URI and opens dropbox.com. And because of Point 5.4. you are not able to hit the back button in your browser to login again because the hash is gone.

2

I'm not sure I would have constructed the solution that way. Instead, I would post all the data to a web service (using HttpWebRequest, as @Loci described, or just importing the service using Visual Studio), which would store the data in a database (perhaps with a pending status). Then direct the user (using your Process.Start approach) to a page that would display the pending help ticket, which would allow them to either approve or discard the ticket.

It sounds like a bit more work, but it should clean up the architecture of what you are trying to do. Plus you have the added benefit of not worrying about how to trigger a form post from the client side.

Edit:

A plain ASMX web service should at least get you started. You can right-click on your project and select Add Service Reference to generate the proxy code for calling the service.

2
  • Thanks! but that, unfortunately is well beyond me at the moment. I will do some research and see if i can get something like that to work and post my results.
    – Ben
    Commented Apr 12, 2012 at 13:46
  • 1
    Good news! this is no longer beyond me so I have accepted your answer (4 years late)!
    – Ben
    Commented Oct 28, 2016 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.