Download large number of files on local server in

In my application I have a option where user can upload their files on our Google Drive account.
Now we added a option where user can use his own Google Drive to store files uploaded from my application.
When user switch from our Google Drive to their own than we need to transfer all files from our Google drive to theirs.

I have written all code to do,
1. I download all files from our Google drive to one server.
2. then from this server I upload them to Users Google Drive.

I am using below code to download files asyn way but this keep failing and throwing errors on the "Completed" event.

The error in maximum times is this
An exception occurred during a WebClient request.
System.Net.WebException: An exception occurred during a WebClient request. ---> System.IO.IOException: The process cannot access the file 'E:\GoogleDataUpload\Files\5\11-409.PDF' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath),

I need to know is there any other way of downloading files or in this code only can I do some change to make it work.

   static void DownloadFile(string url, string fileName, Int64 kiaSerialId, Int64? articleAttachmentID, Int64? articleID, string googleFileId, bool isGoogleDoc)
            WebClient webClient;
            string filePath;

            filePath = CommonMethods.GetDownloadedPath(fileName, kiaSerialId);
                webClient = new WebClient();
                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                webClient.QueryString.Add("fileName", filePath);
                webClient.QueryString.Add("kiaSerialId", kiaSerialId.ToString());
                webClient.QueryString.Add("articleAttachmentID", articleAttachmentID.ToString());
                webClient.QueryString.Add("articleID", articleID.ToString());
                webClient.QueryString.Add("googleFileId", googleFileId);
                webClient.QueryString.Add("isGoogleDoc", isGoogleDoc.ToString());
                webClient.DownloadFileAsync(new Uri(url), filePath);
                //webClient.DownloadFile(new Uri(url), CommonMethods.GetDownloadedPath(fileName, kiaSerialId));                
            catch (Exception ex)
                _stringBuilder.AppendLine("Error in downloading");



        private static void Completed(object sender, AsyncCompletedEventArgs e)
            WebClient client = (WebClient)sender;
            if (e.Error == null)
                //EventLogs.LogInformation("File Downloaded");
                EventLogs.LogError("Error in Downloading \n" + e.Error.Message + "\n" + e.Error);                

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
you have to wait for the WebClient.DownloadFileCompleted Event to fire before you start uploading! files in

There are other ways i.e. transferring ownership!msg/docs/taeiTt_vNFo/DAEIp3YyfysJ

Docs format and for folders ownership can be transferred. First you share with the new account and then you enter the share dialogue again and transfer ownership. I recommend to do this first for folders and then for the Docs files within those folders.!msg/docs/taeiTt_vNFo/DAEIp3YyfysJ

There is always google takeout

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.