Object reference not set to an instance of an object vb class



im uploading file using xml


i have the vb class:



Imports System.Collections.Specialized
Imports System.Net
Imports System.Xml.Linq
Imports System.IO
Namespace DesktopNow.Clases
Class DesktopNowUpload

#Region "Imgur"
Public Shared Function uploadToImgur(ByVal drawed As String) As System.Collections.Generic.IEnumerable(Of XElement)
' Try
Using w = New WebClient()
Dim values = New NameValueCollection() From { _
{"api_key", "iic00n6yokd"}, _
{"file", Convert.ToBase64String(File.ReadAllBytes(drawed))} _
}
'Try
Dim response As Byte() = w.UploadValues("http://ift.tt/13f4GHU", values)

Dim response2 As XDocument = XDocument.Load(New MemoryStream(response))

Dim list As System.Collections.Generic.IEnumerable(Of XElement) = response2.Elements()

Return list


End Using
' Catch s As Exception
' MessageBox.Show("Something went wrong. " & s.Message)
'Return "Failed!"
' End Try
End Function
#End Region



End Class
End Namespace


and the button i use to upload image:



If MsgBox("Comenzando la subida a Imgur..", MsgBoxStyle.Information, "Imgur") = MsgBoxResult.Ok Then

Dim Folder As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments) + "\ScreenUploader\temp\"

If Not Directory.Exists(Folder) Then
Directory.CreateDirectory(Folder)
End If
Dim extension As String = Path.GetExtension(TextBox1.Text).ToLower
'Button1.Text = extension
Dim fuckyoufile As String = Folder + "screen" + extension
If extension = ".jpg" Then
PictureBox1.Image.Save(fuckyoufile, System.Drawing.Imaging.ImageFormat.Jpeg)
ElseIf extension = ".png" Then
PictureBox1.Image.Save(fuckyoufile, System.Drawing.Imaging.ImageFormat.Png)
ElseIf extension = ".gif" Then
PictureBox1.Image.Save(fuckyoufile, System.Drawing.Imaging.ImageFormat.Gif)
ElseIf extension = ".bmp" Then
PictureBox1.Image.Save(fuckyoufile, System.Drawing.Imaging.ImageFormat.Bmp)
End If
Try
Dim info As System.Collections.Generic.IEnumerable(Of XElement) = DesktopNow.Clases.DesktopNowUpload.uploadToImgur(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments) + "\ScreenUploader\temp\screen" + extension)

For Each element As XElement In info

imgurdone.Show()
imgurdone.TextBox1.Text = element.Element("link").Value
imgurdone.TextBox2.Text = element.Element("delete").Value
'MessageBox.Show(element.Element("imgur_page").Value)
'MessageBox.Show(element.Element("delete_page").Value)

Next
Catch s As Exception
'MsgBox("Error SC23" + vbCrLf + "No hay conexion a internet. " + vbCrLf + "Intentalo mas tarde.", MsgBoxStyle.Critical, "Error")
MessageBox.Show("Something went wrong. " & s.Message)
'Return "Failed!"
End Try
File.Delete(fuckyoufile)
PictureBox1.Image = My.Resources.drag1


' End Try
End If


i always the exception:


Object reference not set to an instance of an object


MessageBox.Show("Something went wrong. " & s.Message)


No comments:

Post a Comment