12

I am working on project where I have to access SharePoint data in C#.

I've never done this before; and have the following questions?

How would I access SharePoint data from C#? What API do I use? Are there any tutorials out there that will help me get started?

George Stocker
  • 57,289
  • 29
  • 176
  • 237
Preeti
  • 1,386
  • 8
  • 57
  • 112

7 Answers7

10

There two ways in which you can access Sharepoint data:

  1. By Using Microsoft.Sharepoint.dll In this case you need to do coding on same machine (windows server).

  2. Second way is to use Sharepoint Web Services. This will allow developer to do developement work on different machine.

Preeti
  • 1,386
  • 8
  • 57
  • 112
  • 2
    3. There now is a client api (object model). It is described [here](http://msdn.microsoft.com/en-us/library/ee857094.aspx) – Dänu Jul 24 '12 at 15:33
5

The SDK is a good place to start. The real crux of question lies in whether you are writing code which will live in a SharePoint environment, or writing code which will consume SharePoint data in an external application.

In the case of the former, SharePoint has its own API which you gain access to by simply referencing the appropriate DLL.

For the latter, SharePoint comes with a set of web services which allow external applications to consume its data. Either these or a set of custom services (running in the SharePoint environment) will be your entry point into SharePoint.

Preston Guillot
  • 6,493
  • 3
  • 30
  • 40
3

This is how you would do it in PowerShell which is very similar in how you would do it in in C#:

# Lets reference the assembly / GAC that we need for this
function getUsers
{
    param ([string] $verify_sitepath="https://extranet.something.com")
    $verify_site=new-object Microsoft.SharePoint.SPSite($verify_sitepath)
        $verify_web=$verify_site.Rootweb
    $verify_web.site.url
    $verify_groups = $verify_web.groups | ? {$_.Name -match "^.*$CurrentGroup" }
    foreach($verify_group in $verify_groups)
    {
        foreach($verify_user in $verify_group.users)
        {
            $verify_user = $verify_user -replace "WRKGRP\\",""
            Write-Output "$verify_user" | Out-File -filepath "$splist$currentGroup.txt" -append
        }
    }
}

What this does is gets all the users from SharePoint that are in a text file. Hopefully this gets you at least thinking about how SharePoint is set up.

A great resource is the MSDN page with all the functions. They provide a lot of programming samples in C#!

Mitchell Skurnik
  • 1,419
  • 4
  • 25
  • 37
1

Start at the Sharepoint SDK page. Download the SDK, and look at the sample code on MSDN.

Added later: according to MS, this is a better site for all things related to Sharepoint development.

Traveling Tech Guy
  • 27,194
  • 23
  • 111
  • 159
0

You have to install VS 2005 or VS 2008 extensions for sharepoint. Intsllaing them on xp can be tricky and this page should hep you with that.

Shoban
  • 22,920
  • 8
  • 63
  • 107
  • AFAIK its not included. The SDK system requirements as for this. – Shoban Nov 14 '09 at 07:36
  • 1
    You do NOT need the Visual Studio extensions for SharePoint to start coding against the SharePoint API. The extensions exist solely as a packaging tool, and do a rather poor job of that. This is getting world's better for SharePoint/Visual Studio 2010, but for now 3rd party alternatives for building SharePoint deployables (popular ones are WSPBuilder and STSDEV) are held and shoulders above the Microsoft offerings. – Preston Guillot Nov 14 '09 at 23:11
0

you should also CAML Query which you should know to query data from sharepoint lists
you can make use of such a tool http://www.u2u.be/Res/Tools/CamlQueryBuilder.aspx

Amr Badawy
  • 7,453
  • 12
  • 49
  • 84
0

To me it sounds like you should use the Out Of The Box SharePoint web services. There is no reason why you should have to learn the entire SharePoint API when you could get along just talking to the web service.

This primer on InfoQ is good, but do a seach on SharePoint Web Services and you will find plenty of sources

Kasper
  • 1,710
  • 2
  • 17
  • 31