Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

Upload to Pastebin class

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:
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 Class

Example 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)
That's a nice share. Thanks for this !
So why exactly did you make another thread about it? Does the other one not work properly?
(Jan 24, 2013 11:54 AM)Percocet Wrote:  So why exactly did you make another thread about it? Does the other one not work properly?

It can be found easier when it's a standalone thread and the code is a bit cleaner.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by lockheadApr 22, 2021 07:10 AM 0 145 Apr 22, 2021 07:10 AM
Last Post: lockhead
[Python] by EnskyFeb 5, 2017 04:13 PM 8 424 Feb 5, 2017 04:13 PM
Last Post: Ensky
[C#] by FileBossOct 23, 2016 11:41 AM 1 592 Oct 23, 2016 11:41 AM
Last Post: 'Cynical