Reputation: 11
I've found multiple sites that tell me how to access a Sharepoint site remotely but none seem to explain let alone answer what I am experiencing.
I created a simple C# console app
Within the app I reference:
Microsoft.Sharepoint
,
Microsoft.Sharepoint.Client
, and
Microsoft.Sharepoint.Client.Runtime
I am able to create using statements for Microsoft.Sharepoint
and Microsoft.Sharepoint.Client
but I do not get intellisense for Microsoft.Sharepoint.Client.Runtime
(I only get Applications, Utilities, WebParts and Workflow in the drop down window) -- If I type in using Microsoft.Sharepoint.Client.Runtime
, I get the "red squiggles" under Runtime
Commenting out the Microsoft.Sharepoint.Client.Runtime
, I then enter the following code:
const string FORMAT = "{0}: {1}";
string strURL = "http://<the SPS site address>";
List<string> listFields = new List<string>();
using (SPSite oSite = new SPSite(strURL))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
foreach (SPList list in oWeb.Lists)
{
foreach (SPField field in list.Fields)
{
listFields.Add(string.Format(FORMAT, list.ID, field.Title));
}
}
}
}
Note: At this point in time, there are no errors reported in the error list
I then compile the code (Rebuild) -- At that point I get:
Upvotes: 0
Views: 527
Reputation: 847
If you're not developing on a computer with SharePoint installed on it you can't use those SSOM objects.
You should use their CSOM equivalent.
SPSite - Site
SPWeb - Web
SPList - List
Check out MSDN for other objects.
You will only need the reference to Microsoft.SharePoint.Client
Here's an example from MSDN to retrieve items from a list:
string siteUrl = "http://MyServer/sites/MySiteCollection";
ClientContext clientContext = new ClientContext(siteUrl);
SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='ID'/>" +
"<Value Type='Number'>10</Value></Geq></Where></Query><RowLimit>100</RowLimit></View>";
ListItemCollection collListItem = oList.GetItems(camlQuery);
clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach (ListItem oListItem in collListItem)
{
Console.WriteLine("ID: {0} \nTitle: {1} \nBody: {2}", oListItem.Id, oListItem["Title"], oListItem["Body"]);
}
Upvotes: 1