Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How could I find the fields of a SharePoint list from database in SharePoint 2010?

In SharePoint 2003 and 2007, there was a table called AllLists which had a column called tp_Fields which contained an xml containing all fields for a specific list.

an example of the xml stored in the tp_Fields column would be this for a SharePoint List with 3 fields:

<FieldRef Name="ContentTypeId" />
<FieldRef Name="_ModerationComments" ColName="ntext1" />
<FieldRef Name="WebPartTypeName" ColName="nvarchar9" />

We have an application that is reading from this column using C# code e.g.

var tpFields = (String) drView["tp_Fields"];

In SharePoint 2010, the datatype of this column has changed to varbinary and contains just some binary data instead!

(I know the ideal/recommended solution was to use the SharePoint web services or SharePoint object model and not relying on the underlying tables but unfortunately we have an existing app and we'd need to make it work with 2010 as well. I hope we don't have to redesign everything!)

How could I know what fields a SharePoint list has from its database in SharePoint 2010? or if possible how to convert this varbinary column to its equivalent xml like before?

I hope the question is clear (have little hope about its possibility tbh).

Thanks,

like image 993
The Light Avatar asked Nov 05 '22 07:11

The Light


1 Answers

Just to share, I wrote the below method and it can now extract the xml from it although there is no quarantee the resulting xml is compatible with SharePoint 2003/2007.

 private static string getXmlFromTpFields(byte[] tpFields)
        {
            using (var memoryStream = new MemoryStream(tpFields))
            {
                // ignore the first 14 bytes; I'm not sure why but it works!
                for (var index = 0; index <= 13; index++)
                    memoryStream.ReadByte();

                var deflateStream = new DeflateStream(memoryStream, CompressionMode.Decompress);

                using (var destination = new MemoryStream())
                {
                    deflateStream.CopyTo(destination);

                    var streamReader = new StreamReader(destination);
                    destination.Position = 0;
                    return streamReader.ReadToEnd();
                }
            }
        }
like image 99
The Light Avatar answered Nov 07 '22 21:11

The Light