How do you Read SharePoint Lists Programmatically?

2020-03-11 06:37发布

问题:

I currently use the Linq to SharePoint to retrieve data from several SharePoint lists.

This is my current preferred method of coding my way from ASP.NET and WinForms to retrieve this data.

My only issue with this project:

I have to manually generate the SPML file and add this to the development environment, compile it in the project, and only then I am able to use it to connect to the List.

This is great for projects that require connecting to the one and the same list always.

But I am having users creating new workspaces (sites) with each its own List from which I want to retrieve data automagically (same as linq to sharepoint does, but not statically).

Can you recommend your preferred way of accessing data from several SharePoint Lists and sites in C# WinForms and/or ASP.NET outside an actual SharePoint environment where I can specify the a new source site and list at run time?

回答1:

You have several options both of which are going to require further research on your part they are:

  1. Use the SharePoint object model (Microsoft.Sharepoint.dll), you must be on a PC within the SharePoint farm.
  2. Use the SharePoint web services which can be found at SiteURL/_vti_bin/ you might want to start with Lists.asmx and work from there.

You are going to need some further research as I have said, but remember GIYF.



回答2:

I would really encourage everyone on this topic to have a look at the ado.net driver for sharepoint from bendsoft.com. It is free for developers to use and allows you to query sharepoint information using standard sql syntax and takes care of all sorts of conversion for you.

Dim conn As New SharePointConnection("Server=mysharepointserver.com;Database=sitepath;User=spuser;Password=******;")
conn.Open()
Dim cmd As New SharePointCommand("UPDATE Employees SET Salary = 3250.50 WHERE Name = 'Steve Watson'", conn)
cmd.ExecuteNonQuery()