Hi , thanks for quick reply.
I am using .NET not ASP classic.
I have a page where fileuploadcontrol has been placed.and a button yo upload file.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Button click is as follows
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim sap As New SlideShareAPI.SlideShareAPI.slideshare
sap.initializeKeys("apikey", "secret")
Dim bytes As Byte()
'Get the posted file
Dim fileDataStream As IO.Stream = slideshow_srcfile.PostedFile.InputStream
'Get length of file
Dim fileLength As Integer = slideshow_srcfile.PostedFile.ContentLength
'Create a byte array with file length
Dim fileData(fileLength) As Byte
'Read the stream into the byte array
fileDataStream.Read(fileData, 0, fileLength)
'get the filename
Dim fileTitle As String = slideshow_srcfile.Value
'get the file type
Dim fileType As String = slideshow_srcfile.PostedFile.ContentType
sap.UploadSlide("name", fileData, fileType)
this uploadSlide function is in the dll
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
and is as follows
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim parameters As String = ((("api_key=" & api_key & "&ts=") + timestamp & "&hash=") + CalculateSHA1(shared_secret + timestamp, Encoding.UTF8) & "&slideshow_title=") + slideName '& "&slideshow_srcfile=" + SlideSRC
parameters &= "&username=username" & "&password=password"
Dim reader As String = executeUploadCommand(parameters, slideName, type, SlideSRC)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
now executeUploadCommand is as follows
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim boundary As String = "----WhatIsTheBoundary"
If api_key Is Nothing OrElse shared_secret Is Nothing OrElse timestamp Is Nothing Then
Return "Keys must be initialized first"
End If
Dim webRequest__1 As WebRequest = WebRequest.Create("
http://www.slideshare.net/api/1/upload_slideshow")
webRequest__1.ContentType = "multipart/form-data; boundary=" & boundary
webRequest__1.Method = "POST"
webRequest__1.Timeout = 600000
Dim keys As String() = parameters.Split(New Char() {"&"c})
' Set the body of request
Dim sb As New StringBuilder
sb.Append("--")
sb.Append(boundary)
sb.Append(vbCr & vbLf)
For i As Integer = 0 To keys.Length - 1
Dim param As String() = keys(i).Split(New Char() {"="c})
sb.Append("Content-Disposition: form-data; name=""" & param(0) & """")
sb.Append(vbCr & vbLf)
sb.Append(vbCr & vbLf)
sb.Append(param(1))
sb.Append(vbCr & vbLf)
sb.Append("--")
sb.Append(boundary)
sb.Append(vbCr & vbLf)
Next
sb.Append("Content-Disposition: form-data; name=""" & "slideshow_srcfile" & """")
sb.Append("; filename=""" & fname & """")
sb.Append(vbCr & vbLf)
sb.Append("Content-Type:" & [ctype])
sb.Append(vbCr & vbLf)
sb.Append(vbCr & vbLf)
Dim message As String = sb.ToString()
Dim bytes As Byte() = Encoding.UTF8.GetBytes(message)
Dim msgbyte As Byte() = New Byte(bytes.Length + (file.Length - 1)) {}
Array.Copy(bytes, msgbyte, bytes.Length)
Array.Copy(file, 0, msgbyte, bytes.Length, file.Length)
' Ending Boundry
Dim sb2 As New StringBuilder
sb2.Append("--")
sb2.Append(boundary)
sb2.Append("--")
Dim message2 As String = sb2.ToString()
Dim bytes2 As Byte() = Encoding.UTF8.GetBytes(message2)
Dim msgbyte2 As Byte() = New Byte(bytes2.Length + (msgbyte.Length - 1)) {}
Array.Copy(msgbyte, msgbyte2, msgbyte.Length)
Array.Copy(bytes2, 0, msgbyte2, msgbyte.Length, bytes2.Length)
Dim os As Stream = Nothing
Try
webRequest__1.ContentLength = msgbyte2.Length
os = webRequest__1.GetRequestStream()
os.Write(msgbyte2, 0, msgbyte2.Length)
Catch ex As WebException
Return ex.ToString()
Finally
If os Is Nothing = False Then
os.Close()
End If
End Try
Try
Dim webResponse As WebResponse = webRequest__1.GetResponse()
If webResponse Is Nothing Then
Return Nothing
End If
Dim sr As New StreamReader(webResponse.GetResponseStream())
Return sr.ReadToEnd().Trim()
Catch ex As WebException
Return ex.ToString()
End Try
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
whenever i execute this. an error is returned "Invalid Extension"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
I think there is problem in executeUploadCommand.
Please review this code.and reply me.