Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i am using onedrive rest api to upload files to onedrive. it uses client.asyncupload method to upload files to the onedrive. it works fine but not able to show percentage or progress about the file to be upload. can someone have any ref for this?

below is my code to upload file to the onedrive.

C#
private void cmdBrowseAndUpload_Click(object sender, EventArgs e)
        {
            string fileName = string.Empty;
            using (var dlg = new OpenFileDialog())
            {
                dlg.Filter = "All Files|*.*";
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    fileName = dlg.FileName;
                }
            }
            string url = string.Format(@"https://apis.live.net/v5.0/me/skydrive/my_documents/files/{0}?access_token={1}",
                Path.GetFileName(fileName), access_token);
            using (var client = new WebClient())
            {
                client.UploadDataAsync(new Uri(url), "PUT", ImageToByteArray(fileName));
            }
        }
Posted

1 solution

Hello

Use the web client UploadProgressChanged event

C#
private void cmdBrowseAndUpload_Click(object sender, EventArgs e)
        {
            string fileName = string.Empty;
            using (var dlg = new OpenFileDialog())
            {
                dlg.Filter = "All Files|*.*";
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    fileName = dlg.FileName;
                }
            }
            string url = string.Format(@"https://apis.live.net/v5.0/me/skydrive/my_documents/files/{0}?access_token={1}",
                Path.GetFileName(fileName), access_token);
            using (var client = new WebClient())
            {
client.UploadProgressChanged += new UploadProgressChangedEventHandler(client_UploadProgressChanged);
                client.UploadDataAsync(new Uri(url), "PUT", ImageToByteArray(fileName));
            }
        }



C#
void client_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
       {
           //To do you code here.
           //Progress changed code here
       }
 
Share this answer
 
Comments
ravikhoda 27-Oct-14 7:08am    
thank you very much.

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