How to access sharepoint data using C#?
Asked Answered
C

7

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?

Circinate answered 14/11, 2009 at 6:42 Comment(0)
C
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.

Circinate answered 1/2, 2010 at 7:17 Comment(1)
3. There now is a client api (object model). It is described hereHardspun
H
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.

Howe answered 14/11, 2009 at 23:15 Comment(0)
S
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#!

Sard answered 16/11, 2009 at 15:14 Comment(0)
H
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.

Hyder answered 14/11, 2009 at 6:49 Comment(2)
How is this related to the VS extensions? Are they included?Blurb
No they are not. I've added another link to my original post with the definitive site for Sharepoint development. You can find more info and download VS extensions for Sharepoint from there.Hyder
B
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.

Botticelli answered 14/11, 2009 at 6:58 Comment(2)
AFAIK its not included. The SDK system requirements as for this.Botticelli
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.Howe
D
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

Delly answered 14/11, 2009 at 10:30 Comment(0)
S
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

Shetler answered 15/11, 2009 at 10:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.