C# and SharePoint Backend

17 Mar

I have been using sharepoint lists for my GIS data. My only problem is I’m using different methods in an attempt to get the data out in the fastest and easiest way. I am using haufe.sharepoint and feedparser to use webservices and RSS feeds to parse the data. I have been trying to figure out how to get in to the SQL Server that holds all the goodies. Well, I finally got setup with the info I needed-like an account. Tried pyodbc and had trouble querying – converting uuid to GUID and a few other issues. I switched to C# and the solution was simple. The structure-to get list data-of the sharepoint backend is database>site name>dbo.AllUserData.
Here is some simple code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.IO;

namespace sp
{
class Program
{
static void Main(string[] args)
{
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = “Data Source=123.45.678;”+ “Initial Catalog=Sitedb name;” + “User id=id;” + “Password=pwd;”;

try
{
myConnection.Open();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}

try
{
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand(“select * from dbo.AllUserData where tp_ListId=’2264655-7575-484f-b2576-4d546643esv465dgg'”,
myConnection);
myReader = myCommand.ExecuteReader();

while (myReader.Read())
{

//Do something with data
//where [] is field name.
myReader[‘nvchar14’].ToString();

}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}

try
{
myConnection.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: