Downloading Folders as Zip Files c#

Hemanth B 886 Reputation points
2021-06-08T06:07:23.487+00:00

I created a code that downloads OneDrive folders as zip folders. When the file's downloaded, I checked it was there but when I opened it, it was a displaying an error message saying, the compressed(zip) folder is invalid. Is the below code correct for downloading folders as zip files?

string myWebUrlFile = "https://1drv.ms/u/s!Ag_<PII partly redacted>J4YfbyjUd?e=wER6Se";
// Local path where the file will be saved
string myLocalFilePath = "C:/Users/xxxxx/Pictures/Download.zip";
using (var client = new WebClient())
{
client.DownloadFile(myWebUrlFile, myLocalFilePath);
}

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,169 questions
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,631 Reputation points
    2021-06-09T02:49:38.477+00:00

    Hi HemanthB-9452,
    The problem is your file path.
    I suggest you find the file path by following steps:
    Go to One Drive on the web and right-click on the file that we want and select Embed. Τhen on the right we see the info window to integrate our file into a page. Inside the iframe is the source of the file. Then we have to replace the word embed with the word download and that's it.

     string myWebUrlFile = "https://onedrive.live.com/download?cid=63959A1D954EE80F&resid=63959A1D954EE80F%2110492&authkey=ABQoKVOGlCY54Gk&em=2";  
    

    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    email-notifications.htmlElba-3401


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.