Hi Gee,
Thank you for your interest.
I resolved my problem and i can upload slides now.
This is my uploadFunction:
private static string executeUploadCommand(string parameters, string
fname, string ctype, byte[] file)
{
string boundary = "----WhatIsTheBoundary";
if (api_key == null || shared_secret == null || timestamp
== null)
return "Keys must be initialized first";
WebRequest webRequest = WebRequest.Create("http://
www.slideshare.net/api/1/upload_slideshow");
webRequest.ContentType = "multipart/form-data; boundary="
+ boundary;
webRequest.Method = "POST";
webRequest.Timeout = 60000;
string[] keys = parameters.Split(new char[] { '&' });
// Set the body of request
StringBuilder sb = new StringBuilder();
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
for (int i = 0; i < keys.Length; i++)
{
string[] param = keys[i].Split(new char[] { '=' });
sb.Append("Content-Disposition: form-data; name=\"" +
param[0] + "\"");
sb.Append("\r\n");
sb.Append("\r\n");
sb.Append(param[1]);
sb.Append("\r\n");
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
}
sb.Append("Content-Disposition: form-data; name=\"" +
"slideshow_srcfile" + "\"");
sb.Append("; filename=\"" + fname + "\"");
sb.Append("\r\n");
sb.Append("Content-Type:" + ctype);
sb.Append("\r\n");
sb.Append("\r\n");
string message = sb.ToString();
byte[] bytes = Encoding.UTF8.GetBytes(message);
byte[] msgbyte = new byte[bytes.Length + file.Length];
Array.Copy(bytes, msgbyte, bytes.Length);
Array.Copy(file, 0, msgbyte, bytes.Length, file.Length);
// Ending Boundry
StringBuilder sb2 = new StringBuilder();
sb2.Append("--");
sb2.Append(boundary);
sb2.Append("--");
string message2 = sb2.ToString();
byte[] bytes2 = Encoding.UTF8.GetBytes(message2);
byte[] msgbyte2 = new byte[bytes2.Length +
msgbyte.Length];
Array.Copy(msgbyte, msgbyte2, msgbyte.Length);
Array.Copy(bytes2, 0, msgbyte2, msgbyte.Length,
bytes2.Length);
Stream os = null;
try
{
webRequest.ContentLength = msgbyte2.Length;
os = webRequest.GetRequestStream();
os.Write(msgbyte2, 0, msgbyte2.Length);
}
catch (WebException ex)
{
return ex.ToString();
}
finally
{
if (os != null)
{
os.Close();
}
}
try
{
WebResponse webResponse = webRequest.GetResponse();
if (webResponse == null)
{ return null; }
StreamReader sr = new StreamReader
(webResponse.GetResponseStream());
return sr.ReadToEnd().Trim();
}
catch (WebException ex)
{
return ex.ToString();
}
}
I know that comments are missing But it may help other friends.
Its a sample for uploading slides to slideshare via api v1.0
Thank you and your developer team.
Best,
Blumpy.tr