Interaction with sharepoint, severals ways?
I've been looking for interaction with Sharepoint from a C# code. Basically, it will be a small application which will add/remove data to a remote sharepoint server.
I've found a lot of things, but essentially two things:
Once we access with a "ClientContext", and after we have a "Site", on which we can found "List", etc...
The other thing I found is to access with "SPSite", and we 开发者_开发百科have "SPList", "SP...", etc..
Am I right? Is this two different to access data? Why this? Which one should I use? On what it depends?
Is there some more possibilites with one of these ways?
Thank you very much :)
Edit: I don't know why, I cannot put a "Hi," at the start of my question, sorry :/
The ClientContext
, Site
, Web
and List
classes are part of SharePoint's client object model. They allow you to manipulate SharePoint objects from any client machine.
The SPContext
, SPSite
, SPWeb
and SPList
classes are part of SharePoint's server object model. They allow you to manipulate SharePoint objects from code deployed on the SharePoint servers themselves.
These two technologies are not used in the same way. For instance, query filtering and bulking are important concepts of the client object model, but not of the server object model.
In addition to Frédéric Hamidi excellent answer.
This is most likely what you are looking for http://www.bendsoft.com/net-sharepoint-connector/. It connects through the SharePoint API so you can use it for both internal and external development of SharePoint. Foremost you don't need to learn CAML and use SQL instead.
Example
Insert some data
public void SharePointConnectionExample1()
{
using (SharePointConnection connection = new SharePointConnection(@"
Server=mysharepointserver.com;
Database=mysite/subsite
User=spuser;
Password=******;
Authentication=Ntlm;
TimeOut=10;
StrictMode=True;
RecursiveMode=RecursiveAll;
DefaultLimit=1000;
CacheTimeout=5"))
{
connection.Open();
using (SharePointCommand command = new SharePointCommand("UPDATE `mytable` SET `mycolumn` = 'hello world'", connection))
{
command.ExecuteNonQuery();
}
}
}
Or to select list data to a DataTable
string query = "SELECT * FROM list";
conn = new SharePointConnection(connectionString);
SharePointDataAdapter adapter = new SharePointDataAdapter(query, conn);
DataTable dt = new DataTable();
adapter.Fill(dt);
Or using a helper method to fill a DataGrid
string query = "Select * from mylist.viewname";
DataGrid dataGrid = new DataGrid();
dataGrid.DataSource = Camelot.SharePointConnector.Data.Helper.ExecuteDataTable(query, connectionString);
dataGrid.DataBind();
Controls.Add(dataGrid);
Take my word for it, this turn SharePoint development into a lot of fun!
Cheers
精彩评论