Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Send Clipboard Contents to Pastebin

Description
This macro sends the contents of your clipboard to
Pastebin as a new paste, and returns the new Pastebin URL to your clipboard for immediate pasting.
Language
C#.net
Minimum Version
Created By
Rinyre
Contributors
warthurton
Date Created
Jun 15, 2015
Date Last Modified
Nov 17, 2017

Macro Code

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.IO;

public static class ClipboardFusionHelper
{
	public static string ProcessText(string text)
	{
		System.Collections.Specialized.NameValueCollection Data = new System.Collections.Specialized.NameValueCollection();

		Data["api_paste_name"] = "ClipboardFusion Paste";
		// Defaults to 1 day, can be changed. See Pastebin API
		Data["api_paste_expire_date"] = "1D";
		Data["api_paste_code"] = text;
		// 0 = public, 1 = unlisted, 2 = private
		Data["api_paste_private"] = "1";
		Data["api_dev_key"] = "<API Key>";
		Data["api_option"] = "paste";

		using( WebClient wb = new WebClient() )
		{
			byte[] bytes = wb.UploadValues( "https://pastebin.com/api/api_post.php", Data );

			string response;
			using ( MemoryStream ms = new MemoryStream( bytes ) )
			using ( StreamReader reader = new StreamReader( ms ) )
				response = reader.ReadToEnd();

			if ( response.StartsWith( "Bad API request" ) )
			{
				BFS.Dialog.ShowMessageInfo("Failed to upload. Response: " + response);
				return text;
			}
			else
			{
				BFS.Dialog.ShowMessageInfo("Sent to Pastebin. URL in clipboard.");
				return response;
			}
		}
	}
}