Problem with uploading presentation file (ppt/pps) to Zoho Show with HttpWebRequest in .NET

Problem with uploading presentation file (ppt/pps) to Zoho Show with HttpWebRequest in .NET


I try to upload ppt/pps file from my website, and it work well, but when I use HttpWebRequest object (.NET) to upload and get the response, it crashs.
 
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" ;

//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?

    Access your files securely from anywhere









                          Zoho Developer Community




                                                • Desk Community Learning Series


                                                • Digest


                                                • Functions


                                                • Meetups


                                                • Kbase


                                                • Resources


                                                • Glossary


                                                • Desk Marketplace


                                                • MVP Corner


                                                • Word of the Day


                                                • Ask the Experts



                                                          • Sticky Posts

                                                          • Zoho Office Integrator: Moving to the all-new Zoho Sheet

                                                            We introduced the latest version of Zoho Sheet—Sheet 5—in early 2019. This new version consists of a new user interface, improved performance, and an array of useful features. As a part of this, we will upgrade our Remote API integrations to the new version's editor interface on February 29, 2020. Update: The remote API integrations upgrade to the new version's interface will be done on April 15, 2020. Here are some exciting enhancements the new version of Sheet offers for our API users: An AI-powered
                                                          • Businesses prefer Zoho Office Integrator over Microsoft WOPI - Here's why

                                                            Businesses often have difficult decisions to make when building web applications that provide document management capabilities for their users. For example, what's the best solution to integrate with online office editors— Zoho Office Integrator or Microsoft


                                                          Manage your brands on social media



                                                                Zoho TeamInbox Resources



                                                                    Zoho CRM Plus Resources

                                                                      Zoho Books Resources


                                                                        Zoho Subscriptions Resources

                                                                          Zoho Projects Resources


                                                                            Zoho Sprints Resources


                                                                              Qntrl Resources


                                                                                Zoho Creator Resources



                                                                                    Zoho CRM Resources

                                                                                    • CRM Community Learning Series

                                                                                      CRM Community Learning Series


                                                                                    • Kaizen

                                                                                      Kaizen

                                                                                    • Functions

                                                                                      Functions

                                                                                    • Meetups

                                                                                      Meetups

                                                                                    • Kbase

                                                                                      Kbase

                                                                                    • Resources

                                                                                      Resources

                                                                                    • Digest

                                                                                      Digest

                                                                                    • CRM Marketplace

                                                                                      CRM Marketplace

                                                                                    • MVP Corner

                                                                                      MVP Corner







                                                                                        Design. Discuss. Deliver.

                                                                                        Create visually engaging stories with Zoho Show.

                                                                                        Get Started Now


                                                                                          Zoho Show Resources

                                                                                            Zoho Writer

                                                                                            Get Started. Write Away!

                                                                                            Writer is a powerful online word processor, designed for collaborative work.

                                                                                              Zoho CRM コンテンツ






                                                                                                Nederlandse Hulpbronnen


                                                                                                    ご検討中の方