Jan 24, 2013 11:18 AM
(This post was last modified: Jan 24, 2013 11:19 AM by Delirium™.)
I wrote this piece of code in reference of this thread:
https://hackforums.net/showthread.php?tid=3202604
I wrote this class to make it simply and easy to programmatically upload text/code on pastebin through VB .NET
Credits go to whoever made a post there with code.
Here's the class:
Example usage:
https://hackforums.net/showthread.php?tid=3202604
I wrote this class to make it simply and easy to programmatically upload text/code on pastebin through VB .NET
Credits go to whoever made a post there with code.
Here's the class:
Code
Class PastebinPaster
Dim APIKey As String
Const RequestURL As String = "http://pastebin.com/api/api_post.php"
''' <summary>
''' Constructs the PastebinParser class.
''' </summary>
''' <param name="_APIKey">Your pastebin API dev key.</param>
''' <remarks></remarks>
Sub New(ByVal _APIKey As String)
APIKey = _APIKey
End Sub
''' <summary>
''' The expiry date of your paste (Never, TenMinutes, OneHour, OneDay, OneMonth).
''' </summary>
''' <remarks></remarks>
Structure ExpiryDates
Public Shared Never As String = "N"
Shared TenMinutes As String = "10M"
Shared OneHour As String = "1H"
Shared OneDay As String = "1D"
Shared OneMonth As String = "1M"
End Structure
''' <summary>
''' The privacy of your paste (0 - public, 1 - unlisted, 2 - private).
''' </summary>
''' <remarks></remarks>
Enum PastePrivacy As Short
[Public] = 0
Unlisted = 1
[Private] = 2
End Enum
''' <summary>
''' Uploads your code/text to Pastebin.
''' </summary>
''' <param name="Text">The text to be uploaded.</param>
''' <param name="Title">The title of your paste.</param>
''' <param name="ExpiryDate">The expiry date of your paste.</param>
''' <param name="PastePrivacy">The privacy of your paste.</param>
''' <param name="RawLink">Set to true if you want a direct link to your paste.</param>
''' <returns>The URL to the paste entry (embedded or direct).</returns>
''' <remarks></remarks>
Public Function Paste(ByVal Text As String,
ByVal Title As String, ByVal ExpiryDate As String,
ByVal PastePrivacy As PastePrivacy, ByVal RawLink As Boolean) As String
Dim NameValues As New NameValueCollection
NameValues.Add("api_dev_key", APIKey)
NameValues.Add("api_option", "paste")
NameValues.Add("api_paste_name", Title)
NameValues.Add("api_paste_expire_date", ExpiryDate)
NameValues.Add("api_paste_private", PastePrivacy)
NameValues.Add("api_paste_code", Text)
Dim URL As String = Encoding.Default.GetString(New Net.WebClient().UploadValues(RequestURL, NameValues))
If RawLink Then
Dim PasteID As String = URL.Split("/")(3)
Return "http://www.pastebin.com/raw.php?i=" & PasteID
Else
Return URL
End If
End Function
End ClassExample usage:
Code
Dim Paster As New PastebinPaster("your dev api key")
Dim URL$ = Paster.Paste("Your text", "Your paste's title", PastebinPaster.ExpiryDates.OneHour, PastebinPaster.PastePrivacy.Public, True)
