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();
}
I'm pretty sure that apikey, ticket are correct, the method i use works with other examples, but it doesn't work with Zoho Show Api. Is there any opinion?
Writer is a powerful online word processor, designed for collaborative work.