We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Upload file to dropbox not working ....

I am using Xamarin Studio to develop a proof of concept app with Xamarin Forms based on the Dropbox API  example here ...
https://blogs.dropbox.com/developers/2015/06/introducing-a-preview-of-the-new-dropbox-net-sdk-for-api-v2/

I populate my workbox then save it based on your examples..

                                                          foreach (var item in tmpResult)
                        {
                            rowcount++;
                            worksheetUp.Range["A" + rowcount].Text = item.InspectionItemDescription;
                            worksheetUp.Range["B" + rowcount].Text = item.Category;
                            worksheetUp.Range["C" + rowcount].Text = "Test comment " + item.OID;
                            worksheetUp.Range["D" + rowcount].Text = "Pass";
                        }
                        MemoryStream memstream = new MemoryStream();
                        workbookUp.SaveAs(memstream);
  

Then I try to upload it ....

                                                          var updated = await dbx.Files.UploadAsync("/SPHTEST.xls",
                                WriteMode.Overwrite.Instance,
                                body: memstream);
  

but it gives a general error about reaching the host...I know this is false because it downloads a file 5 lines before it generates this file to be uploaded.

Do I need to write it to storage first ?

Thanks in advance for ANY help you can offer.....

6 Replies

ST StephenH May 8, 2017 04:57 PM UTC

OK, so I changed the iOS "HTTPClient implementation" from managed to NSURLSession and it upload and created the file but it's empty.

can someone .. anyone verify this code is correct and should contain the workbook?

IWorkbook workbookUp = application.Workbooks.Create(1);
                        IWorksheet worksheetUp = workbook.Worksheets[0];
                        int rowcount = 0;
                        foreach (var item in tmpResult)
                        {
                            rowcount++;
                            worksheetUp.Range["A" + rowcount].Text = item.InspectionItemDescription;
                            worksheetUp.Range["B" + rowcount].Text = item.Category;
                            worksheetUp.Range["C" + rowcount].Text = "Test comment " + item.OID;
                            worksheetUp.Range["D" + rowcount].Text = "Pass";
                        }
                        MemoryStream memstream = new MemoryStream();
                        workbookUp.SaveAs(memstream);
 

 


MM Mathu Mohan Vijayakumar Syncfusion Team May 9, 2017 01:29 PM UTC

Hi Stephen, 
 
We suspect that the issue might be occurs due to the stream position is not set after saving the workbook. So, we request you to set the stream position to zero before upload as shown below. 
 
Code Example: 
          
//Saving the workbook as stream 
workbook.SaveAs(stream); 
//Positioning the stream 
stream.Position = 0; 
//Closing the workbook 
workbook.Close(); 
 

Also, we have prepared a sample with the above mentioned changes and the sample can be downloaded from the below link. 
Sample Link: 
 
Kindly try this sample and let us know whether the issue is resolved at your end. 
 
Regards, 
Mathu Mohan V A 



ST StephenH May 9, 2017 01:57 PM UTC

OK, that put a file up there but no data :(This code should work right ?The values are in the worksheet when I debug print them ...     IWorkbook workbookUp = application.Workbooks.Create(1);                         IWorksheet worksheetUp = workbook.Worksheets[0];                         int rowcount = 0;                         foreach (var item in tmpResult)                         {                             rowcount++;                             worksheetUp.Range["A" + rowcount].Text = item.InspectionItemDescription;                             worksheetUp.Range["B" + rowcount].Text = item.Category;                             worksheetUp.Range["C" + rowcount].Text = "Test comment " + item.OID;                             worksheetUp.Range["D" + rowcount].Text = "Pass";                             //Display the values                              Debug.WriteLine(worksheetUp["A" + rowcount].Text);                             Debug.WriteLine(worksheetUp["B" + rowcount].Text);                             Debug.WriteLine(worksheetUp["C" + rowcount].Text);                             Debug.WriteLine(worksheetUp["D" + rowcount].Text);                         }                         MemoryStream memstream = new MemoryStream();                         workbookUp.SaveAs(memstream);                         memstream.Position = 0;                         workbookUp.Close();  


ST StephenH May 9, 2017 01:59 PM UTC

I have pasted the code formatted but it does not keep the formatting when I save it for some reason, am I missing something?




ST StephenH May 9, 2017 03:44 PM UTC

OK, I did some troubleshooting and autocomplete and referenced a similar variable above the one I wanted :(

The additional code segments you provided fixed my issue THANK YOU!



AV Abirami Varadharajan Syncfusion Team May 10, 2017 11:05 AM UTC

Hi Stephen,  
 
Thank you for updating us. 
 
We are glad that the issue is resolved at your end. Please let us know if you need any further assistance. 
 
Regards, 
Abirami. 


Loader.
Up arrow icon