Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
add comment

7 Answers

up vote 7 down vote accepted

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.

share|improve this answer
2  
3. There now is a client api (object model). It is described here –  Dänu Jul 24 '12 at 15:33
add comment

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.

share|improve this answer
add comment

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#!

share|improve this answer
add comment

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.

share|improve this answer
 
Are the VS extensions included in the Sharepoint SDK? –  Robert Harvey Nov 14 '09 at 7:24
 
AFAIK its not included. The SDK system requirements as for this. –  Shoban Nov 14 '09 at 7: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
add comment

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.

share|improve this answer
 
How is this related to the VS extensions? Are they included? –  Robert Harvey Nov 14 '09 at 7:23
 
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. –  Traveling Tech Guy Nov 14 '09 at 9:15
add comment

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

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.