ShareFile-NET icon indicating copy to clipboard operation
ShareFile-NET copied to clipboard

Not able to download the Shared folder files.

Open pvagare opened this issue 8 years ago • 2 comments

I did the following code to download the Shared folder files. Please verify the code and let me know if I am missing something, Please give me exact code for downloading the shared folder files.

Public Async Function Run(user As FileShareDefaultUser, clientId As String, clientSecret As String) As Task

    Dim sfClient = Await PasswordAuthentication(user, clientId, clientSecret)
    Await StartSession(sfClient)

    Dim ShareFolder = Await sfClient.Shares.[Get]().Expand("Children").ExecuteAsync()
	
    For Each feed As Share In shareFolder.Feed

        If feed.Items IsNot Nothing Then
            For Each item As Item In feed.Items
        Await Download(sfClient, uploadedFile)
            Next
        End If
    Next

End Function


Public Async Function Download(sfClient As ShareFileClient, itemToDownload As Item) As Task

    Dim downloadDirectory = New DirectoryInfo("C:\DownloadedFiles")
    If Not downloadDirectory.Exists Then
        downloadDirectory.Create()
    End If

    Dim downloader = sfClient.GetAsyncFileDownloader(itemToDownload)
    Dim file = IO.File.Open(Path.Combine(downloadDirectory.Name, itemToDownload.Name), FileMode.Create)
    Await downloader.DownloadToAsync(file)
End Function

Thanks !

pvagare avatar Dec 26 '16 14:12 pvagare

**Accessing a Share

Assuming you have the url that points to the Share API resource (ex. https://subdomain.sharefile.com/sf/v3/Shares(s0123456789)), you can easily access the Items shared. Depending on the share you may be required to already be authenticated.

var shareUri = new Uri("https://subdomain.sharefile.com/sf/v3/Shares(s0123456789)"); var share = await sfClient.Shares.Get(shareUri); var shareItems = await sfClient.Shares.GetItems(shareUri, share.AliasID); Items associated with a Share cannot be downloaded as you normally might, instead you need to use the Shares API to download.

// assuming you already have shareItems as noted before

var fileStream = await sfClient.Shares.Download(shareUri, share.AliasID, shareItems.Select(x => x.Id).First());**

**I also tried above but giving not able to download the file.

Please give me exact code for downloading the shared files**.

pvagare avatar Dec 26 '16 14:12 pvagare

Hi @pvagare , sorry for the delay I've been on holiday.

What error do you receive when using the documentation sample?

In the code you provided (first comment), one issue I see is you're attempting to expand Children when you'd need to expand Items.

rgmills avatar Jan 14 '17 13:01 rgmills