Click here to Skip to main content
15,921,295 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void btlUpload_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (DBB != null)
                {
                    if (strAccessToken != null && strAuthenticationURL != null)
                    {
                       
                        DBB.Upload("Dropbox/DotNetApi/DLClaim", "Sample", @"D:\Untitled.PNG");
                       
                        
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
            
        }






public bool Upload(string UploadfolderPath, string UploadfileName, string SourceFilePath)
        {
            try
            {
                using (var stream = new MemoryStream(File.ReadAllBytes(SourceFilePath)))
                {
                                       var response = DBClient.Files.UploadAsync("/" + UploadfolderPath + "/" + UploadfileName, WriteMode.Overwrite.Instance, body: stream);                    
                    var rest = response.Result; //Added to wait for the result from Async method  


                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }

        }


What I have tried:

using Dropbox.Api;


I tried to upload a file to Dropbox (like  google Drive). but did not find anything appropriate.
Posted
Updated 8-May-19 3:49am
v2

1 solution

When calling an API, you should be using async and tasks. A quick Google search has many results and if you go trough the structure of the code that is out there you should be able to get this set up easily.

Google Search: msg Id = 1, Status = WaitingForActivation API[^]
 
Share this answer
 
Comments
sujatha111 8-May-19 9:58am    
I tried in this way also but not getting the solution.

public async Task<filemetadata> UploadFileToDropBox(string fileToUpload, string folder)
{
DropboxClient client = new DropboxClient(AccessTocken);

using (var mem = new MemoryStream(File.ReadAllBytes(fileToUpload)))
{
string filename = Path.GetFileName(fileToUpload);

try
{
string megapath = "/Dropbox/DotNetApi/DLClaim";
string megapathWithFile = Path.Combine(megapath, Path.GetFileName(Path.GetFileName(filename))).Replace("\\", "/");
var updated = client.Files.UploadAsync(megapathWithFile, WriteMode.Overwrite.Instance, body: mem);
await updated;
return updated.Result;
}
catch (Exception ex)
{
return null;
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900