What is the best way to query SharePoint data?

Should I just use ADO.NET to directly access the underlying data in the database, or does .NET have a better way to do this?

I am currently using SharePoint 2007, but we are going to move to 2010. I am using Visual Studio 2010.

+3
source share
5 answers

I would highly recommend using SharePoint objects to access data (SP * classes or using the SharePoint web services, LINQ to SharePoint, etc.).

ADO.NET. , , () , . , , . SharePoint .

, , Microsoft SharePoint, , , SP, Microsoft .

+4

Sharepoint?

sharepoint, .

, Entity Framework: http://msdn.microsoft.com/en-us/library/aa697427(VS.80).aspx

+1

. .

?

? -

?

?

-? CQWP (- ) DVWP (- )

?

SharePoint, , - api.

+1

SharePoint.

- , , - . SharePoint, SharePoint. , , .

+1

, . Microsoft , , , , .

SharePoint . , . , , , . , , SharePoint, ( , , MSDN).

1. SPList

, , . SPList SharePoint. , , , . SharePoint - ( ) ( ). SPListItem

2. SPWeb SPSite

, SPSite , SPWeb . , SharePoint hXXp://SharePointSite.com, (SPSite) hXXp://SharePointSite.com, SPWeb hXXp://SharePointSite.com/blog hXXp://SharePointSite.com/ , - SPWeb, SPList ( , ). SPList .

3. SPQuery

SharePoint SQL. LINQ 2 SharePoint 2010 ( 2007, , 2010 ), . SPQueries , . , : foreach(item in SPList.Items) , , SPQuery ( , SQL/ADO)

. , - , , 18 . :

    using(SPSite site = new SPSite("http://sharepointsite.com"))
    {
        using (SPWeb web = site.RootWeb)
        {
            SPList peopleList = web.Lists["People"];
            SPQuery query = new SPQuery();
            query.Query = 
                    "<Where>" +
                        "<Eq>" +
                            "<FieldRef Name='Age'/><Value Type='Number'>18</Value>" +
                        "</Eq>" +
                    "</Where>";

            SPListItemCollection items = peopleList.GetItems(query);

            foreach(SPListItem item in items)
            {
                //item here represents a person who 18 years old.
            }
        }
    }

( ), SPQuery, CAML. , , , , . , , : U2U CAML Builder

, -, . SharePoint, / , -, , SharePoint . , . , , XML, - . .

+1
source

Source: https://habr.com/ru/post/1777753/


All Articles