I want to use .net code. I had found a function which worked for other
but i ge "invalid extension error" when i try this code.
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();
}
}
This code was written by Blumpy.tr .
I am passing the type of file to be uplloaded and bytes of file .
Regards
On Jun 15, 8:28 pm, sri prasanna <
macho...@gmail.com> wrote:
> I remember same thing happened few months back you can check the
> conversation herehttp://
groups.google.com/group/slideshare-developers/browse_thread/th...