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:

  1. public static void Upload(string username, string password, string apiKey, string filePath)   
  2.        {   
  3.            var ticket = GetTicket(username, password);   
  4.            if (string.IsNullOrEmpty(ticket)) return;   
  5.   
  6.            var requestUrl = "http://show.zoho.com/api/private/xml/uploadpresentation?apikey=" +    
  7.                apiKey + "&ticket=" + ticket;   
  8.   
  9.            var request = (HttpWebRequest)WebRequest.Create(requestUrl);   
  10.            request.Method = "POST";   
  11.            //request.Headers = new WebHeaderCollection();   
  12.            //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, */*");    
  13.            string boundary = "-----------------------------" + DateTime.Now.Ticks.ToString("x");   
  14.            //string boundary = "------" + Guid.NewGuid().ToString().Replace("-", "");   
  15.            request.ContentType = "multipart/form-data; boundary=" + boundary;   
  16.            request.KeepAlive = true;   
  17.            request.Credentials =CredentialCache.DefaultCredentials;   
  18.   
  19.   
  20.            var postDataStream = new MemoryStream();   
  21.            const string newLine = "\r\n";   
  22.            var streamWriter = new StreamWriter(postDataStream);   
  23.            streamWriter.Write(boundary + newLine);   
  24.            streamWriter.Write("Content-Disposition: form-data; name=\"content\"; filename=\"" + (new FileInfo(filePath)).Name + "\"" + newLine);   
  25.            streamWriter.Write("Content-Type: application/vnd.ms-powerpoint"+ newLine + newLine);   
  26.            streamWriter.Flush();   
  27.   
  28.            var fileContent = (new FileInfo(filePath)).OpenText().ReadToEnd();   
  29.            streamWriter.Write(fileContent);   
  30.            streamWriter.Write(newLine);   
  31.            streamWriter.Write(boundary+newLine);   
  32.            streamWriter.Flush();   
  33.   
  34.            streamWriter.Write("Content-Disposition: form-data; name=\"submit\"" + newLine + newLine);   
  35.            streamWriter.Write("importpresentation" + newLine);   
  36.            streamWriter.Write(boundary+ "--" + newLine);   
  37.            streamWriter.Flush();   
  38.   
  39.            request.ContentLength = postDataStream.Length;   
  40.            using(var requestStream = request.GetRequestStream())   
  41.            {   
  42.                postDataStream.WriteTo(requestStream);   
  43.            }   
  44.   
  45.            streamWriter.Close();   
  46.            postDataStream.Close();   
  47.            //var content = new StringBuilder();   
  48.            //content.AppendLine(boundary);   
  49.            //content.AppendLine("Content-Disposition: form-data; name=\"content\"; filename=\"" + (new FileInfo(filePath)).Name + "\"");   
  50.            //content.AppendLine("Content-Type: application/vnd.ms-powerpoint");   
  51.            //content.AppendLine("");   
  52.            //var fileContent = (new FileInfo(filePath)).OpenText().ReadToEnd();   
  53.            //content.AppendLine(fileContent);   
  54.            //content.AppendLine(boundary);   
  55.            //content.AppendLine("Content-Disposition: form-data; name=\"submit\"");   
  56.            //content.AppendLine("");   
  57.            //content.AppendLine("importpresentation");   
  58.            //content.AppendLine(boundary + "--");   
  59.            //Console.WriteLine(content);   
  60.            //File.WriteAllText(@"e:\a.txt", content.ToString());   
  61.            //byte[] data = ASCIIEncoding.UTF8.GetBytes(content.ToString());   
  62.            //request.ContentLength = data.Length;   
  63.   
  64.            //var requestStream = request.GetRequestStream();   
  65.            //requestStream.Write(data, 0, data.Length);   
  66.            //requestStream.Close();   
  67.   
  68.            var response = request.GetResponse();   
  69.            // Get the stream containing content returned by the server.   
  70.            var responseStream = response.GetResponseStream();   
  71.            // Open the stream using a StreamReader for easy access.   
  72.            var reader = new StreamReader(responseStream);   
  73.            // Read the content.   
  74.            var responseFromServer = reader.ReadToEnd();   
  75.            Console.WriteLine(responseFromServer);   
  76.            // Display the content.   
  77.            ///ViewData["content"] = responseFromServer;   
  78.            //Console.WriteLine(responseFromServer);   
  79.            // Clean up the streams.   
  80.            reader.Close();   
  81.            responseStream.Close();   
  82.            response.Close();   
  83.        }  

 

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!

 

kick it on DotNetKicks.com

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Posted in: .NET , ASP.NET  Tags:

Page List

    Calendar

    «  September 2010  »
    MoTuWeThFrSaSu
    303112345
    6789101112
    13141516171819
    20212223242526
    27282930123
    45678910
    View posts in large calendar

    Recent Comments

    Disclaimer
    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010 SFI.VN Team