I'm writing a asp.net mvc website that presents PPT file, so I use ZohoShow as storage and Zoho Show Viewer as a presenter.
Zoho Show API to upload a ppt/pps file.
My code:
- public static void Upload(string username, string password, string apiKey, string filePath)
- {
- var ticket = GetTicket(username, password);
- if (string.IsNullOrEmpty(ticket)) return;
-
- var requestUrl = "http://show.zoho.com/api/private/xml/uploadpresentation?apikey=" +
- apiKey + "&ticket=" + ticket;
-
- var request = (HttpWebRequest)WebRequest.Create(requestUrl);
- request.Method = "POST";
-
-
- string boundary = "-----------------------------" + DateTime.Now.Ticks.ToString("x");
-
- request.ContentType = "multipart/form-data; boundary=" + boundary;
- request.KeepAlive = true;
- request.Credentials =CredentialCache.DefaultCredentials;
-
-
- var postDataStream = new MemoryStream();
- const string newLine = "\r\n";
- var streamWriter = new StreamWriter(postDataStream);
- streamWriter.Write(boundary + newLine);
- streamWriter.Write("Content-Disposition: form-data; name=\"content\"; filename=\"" + (new FileInfo(filePath)).Name + "\"" + newLine);
- streamWriter.Write("Content-Type: application/vnd.ms-powerpoint"+ newLine + newLine);
- streamWriter.Flush();
-
- var fileContent = (new FileInfo(filePath)).OpenText().ReadToEnd();
- streamWriter.Write(fileContent);
- streamWriter.Write(newLine);
- streamWriter.Write(boundary+newLine);
- streamWriter.Flush();
-
- streamWriter.Write("Content-Disposition: form-data; name=\"submit\"" + newLine + newLine);
- streamWriter.Write("importpresentation" + newLine);
- streamWriter.Write(boundary+ "--" + newLine);
- streamWriter.Flush();
-
- request.ContentLength = postDataStream.Length;
- using(var requestStream = request.GetRequestStream())
- {
- postDataStream.WriteTo(requestStream);
- }
-
- streamWriter.Close();
- postDataStream.Close();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var response = request.GetResponse();
-
- var responseStream = response.GetResponseStream();
-
- var reader = new StreamReader(responseStream);
-
- var responseFromServer = reader.ReadToEnd();
- Console.WriteLine(responseFromServer);
-
-
-
-
- reader.Close();
- responseStream.Close();
- response.Close();
- }
public static void Upload(string username, string password, string apiKey, string filePath)
{
var ticket = GetTicket(username, password);
if (string.IsNullOrEmpty(ticket)) return;
var requestUrl = "http://show.zoho.com/api/private/xml/uploadpresentation?apikey=" +
apiKey + "&ticket=" + ticket;
var request = (HttpWebRequest)WebRequest.Create(requestUrl);
request.Method = "POST";
//request.Headers = new WebHeaderCollection();
//request.Headers.Add("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-shockwave-flash, */*");
string boundary = "-----------------------------" + DateTime.Now.Ticks.ToString("x");
//string boundary = "------" + Guid.NewGuid().ToString().Replace("-", "");
request.ContentType = "multipart/form-data; boundary=" + boundary;
request.KeepAlive = true;
request.Credentials =CredentialCache.DefaultCredentials;
var postDataStream = new MemoryStream();
const string newLine = "\r\n";
var streamWriter = new StreamWriter(postDataStream);
streamWriter.Write(boundary + newLine);
streamWriter.Write("Content-Disposition: form-data; name=\"content\"; filename=\"" + (new FileInfo(filePath)).Name + "\"" + newLine);
streamWriter.Write("Content-Type: application/vnd.ms-powerpoint"+ newLine + newLine);
streamWriter.Flush();
var fileContent = (new FileInfo(filePath)).OpenText().ReadToEnd();
streamWriter.Write(fileContent);
streamWriter.Write(newLine);
streamWriter.Write(boundary+newLine);
streamWriter.Flush();
streamWriter.Write("Content-Disposition: form-data; name=\"submit\"" + newLine + newLine);
streamWriter.Write("importpresentation" + newLine);
streamWriter.Write(boundary+ "--" + newLine);
streamWriter.Flush();
request.ContentLength = postDataStream.Length;
using(var requestStream = request.GetRequestStream())
{
postDataStream.WriteTo(requestStream);
}
streamWriter.Close();
postDataStream.Close();
//var content = new StringBuilder();
//content.AppendLine(boundary);
//content.AppendLine("Content-Disposition: form-data; name=\"content\"; filename=\"" + (new FileInfo(filePath)).Name + "\"");
//content.AppendLine("Content-Type: application/vnd.ms-powerpoint");
//content.AppendLine("");
//var fileContent = (new FileInfo(filePath)).OpenText().ReadToEnd();
//content.AppendLine(fileContent);
//content.AppendLine(boundary);
//content.AppendLine("Content-Disposition: form-data; name=\"submit\"");
//content.AppendLine("");
//content.AppendLine("importpresentation");
//content.AppendLine(boundary + "--");
//Console.WriteLine(content);
//File.WriteAllText(@"e:\a.txt", content.ToString());
//byte[] data = ASCIIEncoding.UTF8.GetBytes(content.ToString());
//request.ContentLength = data.Length;
//var requestStream = request.GetRequestStream();
//requestStream.Write(data, 0, data.Length);
//requestStream.Close();
var response = request.GetResponse();
// Get the stream containing content returned by the server.
var responseStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
var reader = new StreamReader(responseStream);
// Read the content.
var responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
// Display the content.
///ViewData["content"] = responseFromServer;
//Console.WriteLine(responseFromServer);
// Clean up the streams.
reader.Close();
responseStream.Close();
response.Close();
}
But no matter how i try, Zoho Show server always refuse the request:System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
If there is anybody interested with HttpWebRequest and ZohoShow, please give me some hint to make it works.
Thanks!

eefeaf9b-aef4-435d-adc5-3131a2f7b41d|2|5.0