I'm sorry if this has been asked, but I cannot find an answer. Can you query a SharePoint Document Library or site in a C# program using SQL?
If so, how do you set up the connection to SharePoint with C#?
|
I'm sorry if this has been asked, but I cannot find an answer. Can you query a SharePoint Document Library or site in a C# program using SQL? If so, how do you set up the connection to SharePoint with C#? |
|||
|
|
|
In case you are planning to query a SharePoint database, please don't do that! It's not supported and wrong in many ways. You should use SharePoint APIs to retrieve data you need. You can retrieve items from a SharePoint list via SPList object (not optimal for large list), or if you plan to query a list you should use CAML. |
||||
|
|
You can use FullTextSQLQuery to issue SQL-like queries against the search index. For simply returning a list of items, the standard is to use CAML queries, or LINQ to SharePoint is quickly becoming a popular method of doing this now. Never attempt to directly query the underlying SQL content database, as this is not a supported practice. |
|||
|
|
|
Just to add my $2 on why you shouldn't connect directly to the SQL DB (and should use the SharePoint API as others have said), I blogged about this here: Supported Database Operations in SharePoint 2010. |
|||
|
|