简体   繁体   English

如何使用C#访问sharepoint数据?

[英]How to access sharepoint data using C#?

I am working on project where I have to access SharePoint data in C#. 我正在开发项目,我必须在C#中访问SharePoint数据。

I've never done this before; 我以前从未这样做过; and have the following questions? 并有以下问题?

How would I access SharePoint data from C#? 我如何从C#访问SharePoint数据? What API do I use? 我使用什么API? Are there any tutorials out there that will help me get started? 有没有可以帮助我入门的教程?

There two ways in which you can access Sharepoint data: 有两种方法可以访问Sharepoint数据:

  1. By Using Microsoft.Sharepoint.dll In this case you need to do coding on same machine (windows server). 通过使用Microsoft.Sharepoint.dll在这种情况下,您需要在同一台计算机(Windows服务器)上进行编码。

  2. Second way is to use Sharepoint Web Services. 第二种方法是使用Sharepoint Web Services。 This will allow developer to do developement work on different machine. 这将允许开发人员在不同的机器上进行开发工作。

The SDK is a good place to start. SDK是一个很好的起点。 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. 问题的真正关键在于您是编写将存在于SharePoint环境中的代码,还是编写将在外部应用程序中使用SharePoint数据的代码。

In the case of the former, SharePoint has its own API which you gain access to by simply referencing the appropriate DLL. 对于前者,SharePoint具有自己的API,您可以通过简单地引用相应的DLL来获得访问权限。

For the latter, SharePoint comes with a set of web services which allow external applications to consume its data. 对于后者,SharePoint附带了一组Web服务,允许外部应用程序使用其数据。 Either these or a set of custom services (running in the SharePoint environment) will be your entry point into SharePoint. 这些或一组自定义服务(在SharePoint环境中运行)将成为SharePoint的入口点。

This is how you would do it in PowerShell which is very similar in how you would do it in in C#: 这就是你在PowerShell中的表现,它与你在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. 它的作用是从SharePoint中获取文本文件中的所有用户。 Hopefully this gets you at least thinking about how SharePoint is set up. 希望这至少可以让您思考如何设置SharePoint。

A great resource is the MSDN page with all the functions. 一个很好的资源是具有所有功能的MSDN页面。 They provide a lot of programming samples in C#! 他们在C#中提供了大量的编程示例!

Start at the Sharepoint SDK page . Sharepoint SDK页面开始 Download the SDK, and look at the sample code on MSDN. 下载SDK,并查看MSDN上的示例代码。

Added later: according to MS, this is a better site for all things related to Sharepoint development. 稍后补充:根据MS, 是一个更好的网站,可用于与Sharepoint开发相关的所有事情。

You have to install VS 2005 or VS 2008 extensions for sharepoint. 您必须为sharepoint安装VS 2005或VS 2008扩展 Intsllaing them on xp can be tricky and this page should hep you with that. 在xp上使用它们可能会很棘手,而且这个页面应该让你熟悉它。

you should also CAML Query which you should know to query data from sharepoint lists 您还应该查询CAML查询从sharepoint列表中查询数据
you can make use of such a tool http://www.u2u.be/Res/Tools/CamlQueryBuilder.aspx 你可以使用这样的工具http://www.u2u.be/Res/Tools/CamlQueryBuilder.aspx

To me it sounds like you should use the Out Of The Box SharePoint web services. 对我来说,听起来你应该使用Out of The Box SharePoint Web服务。 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. 当您只是与Web服务交谈时,没有理由要学习整个SharePoint API。

This primer on InfoQ is good, but do a seach on SharePoint Web Services and you will find plenty of sources 这篇关于InfoQ的入门书很好,但是在SharePoint Web Services上进行了一次搜索,你会发现很多资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM