|
-
Nov 2nd, 2016, 01:35 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] Get a list of files using SharePoint.Client
I uploaded thousands of files for a client but some were not allowed and skipped. I want to determine those files now. I was hoping to write a simple app to get a list of all the files on the SharePoint site. However so far all the examples I've found online have been server side and I need to do it using Microsoft.SharePoint.Client in a WinForm program. Can anyone point me to a quick and dirty example online or maybe have a quick one to post here?
-
Nov 2nd, 2016, 01:57 PM
#2
Re: Get a list of files using SharePoint.Client
Are you looking for all the files in a specific SharePoint Library or across the entire site?
-
Nov 2nd, 2016, 01:58 PM
#3
Thread Starter
Frenzied Member
Re: Get a list of files using SharePoint.Client
-
Nov 2nd, 2016, 01:59 PM
#4
Thread Starter
Frenzied Member
Re: Get a list of files using SharePoint.Client
I found a PowerShell script but it needs a SP plugin that I can't seem to get to install.
-
Nov 2nd, 2016, 02:38 PM
#5
Thread Starter
Frenzied Member
Re: Get a list of files using SharePoint.Client
I discovered I can map a network drive to a SP library. I'll use my SizeExplorer Pro program to generate a list from there. Thanks.
-
Nov 2nd, 2016, 02:43 PM
#6
Re: [RESOLVED] Get a list of files using SharePoint.Client
Here you go, try this:
Code:
Public Function GetFiles(folderUri As Uri) As List(Of String)
Dim out As New List(Of String)
Dim server As String = folderUri.AbsoluteUri.Replace(folderUri.AbsolutePath, "")
Dim serverrelative As String = folderUri.AbsolutePath
Dim clientContext As ClientContext = New ClientContext(server)
Dim web As Web = clientContext.Web
Dim folder As Folder = web.GetFolderByServerRelativeUrl(serverrelative)
clientContext.Load(folder, Function(f2) f2.Files)
clientContext.ExecuteQuery()
For Each f As Microsoft.SharePoint.Client.File In folder.Files
out.Add(f.Name)
Next
Return out
End Function
-
Nov 2nd, 2016, 04:09 PM
#7
Thread Starter
Frenzied Member
Re: [RESOLVED] Get a list of files using SharePoint.Client
I think it will work but I'm getting an exception on the ExecuteQuery. 403, forbidden. So I'm thinking we need to add some credentials in here someplace?
-
Nov 2nd, 2016, 04:11 PM
#8
Thread Starter
Frenzied Member
Re: [RESOLVED] Get a list of files using SharePoint.Client
For the URI I used "https://[MyCompanyName].sharepoint.com/[SiteName]/"
-
Nov 3rd, 2016, 02:45 PM
#9
Re: [RESOLVED] Get a list of files using SharePoint.Client
Add this line in there right after Dim clientContext....
Code:
clientContext.Credentials = New Net.NetworkCredential("user", "password", "domain")
Of course, replace the user, password and domain strings with your information, or more securely, the information to a service account you can use to interact with the SharePoint site.
-
Nov 3rd, 2016, 02:57 PM
#10
Thread Starter
Frenzied Member
Re: [RESOLVED] Get a list of files using SharePoint.Client
Looks good but I don't know what the domain value should be. I tried to leave it blank and "MicrosoftAccount" but I'm still getting 403.
-
Nov 3rd, 2016, 03:09 PM
#11
Re: [RESOLVED] Get a list of files using SharePoint.Client
I don't know. We run Sharepoint on a local server, we don't go through sharepoint.com. Typically, it's whatever the domain your computer is attached to on a typical, Windows Server network. Try what you use for [MyCompanyName].
Try using the URL of the actual library for the function, like: https://MyCompanyName.sharepoint.com/SiteName/LibraryName
-
Nov 3rd, 2016, 03:30 PM
#12
Thread Starter
Frenzied Member
Re: [RESOLVED] Get a list of files using SharePoint.Client
Still 403. I was working with one piece of code before that had this and I couldn't find an example anywhere online describing what I should put here. I found a utility called SPFileZilla that has a field for it but i just leave it blank.
-
Nov 3rd, 2016, 03:38 PM
#13
Thread Starter
Frenzied Member
Re: [RESOLVED] Get a list of files using SharePoint.Client
In SPFileZilla I have fields that mimic what we have here and I believe he's using the same library. So I entered a known good set from my client and it's still 403. But in the SPFileZilla there's a checkbox labeled "Is SharePoint Online". I wonder, is there another parameter I should be setting for SP on the web. I'll look into the ClientContext and see if I can find something like that.
-
Nov 3rd, 2016, 03:41 PM
#14
Thread Starter
Frenzied Member
Re: [RESOLVED] Get a list of files using SharePoint.Client
I found to be out on the Internet it needs to be SharePointOnlineCredentials. But it doesn't take a string for a password. I need to figure out how to use "Secure String".
-
Nov 3rd, 2016, 03:59 PM
#15
Thread Starter
Frenzied Member
Re: [RESOLVED] Get a list of files using SharePoint.Client
I worked out the credentials. Must use SharePointOnlineCredentials. Odd fellow. It seems one has to load it one character at a time. Like this:
vb.net Code:
Dim strPassword As String = "MyPassword"
For Each chrTemp As Char In strPassword
ssPassword.AppendChar(chrTemp)
Next
'Then adding the password is...
clientContext.Credentials = New SharePointOnlineCredentials(" [email protected]", ssPassword)
Now there are no exceptions but the list of string is empty. I'll work on that more in a bit.
-
Nov 3rd, 2016, 04:03 PM
#16
Re: [RESOLVED] Get a list of files using SharePoint.Client
Ahh gotcha. Well, if you're not typing things in, you can use this:
Code:
Public Function StringToSecure(str As String) As System.Security.SecureString
Dim c() As Char = str.ToCharArray()
Dim sec As New System.Security.SecureString
For Each letter As Char In c
sec.AppendChar(letter)
Next
Return sec
End Function
-
Nov 3rd, 2016, 04:12 PM
#17
Thread Starter
Frenzied Member
Re: [RESOLVED] Get a list of files using SharePoint.Client
I think that's basically what I did. Maybe our messages passed in the ether.
Any ideas on the zero list items? What about making it recursive? IE sub-directories.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|