How could I find the fields of a SharePoint list f

2019-04-08 19:31发布

问题:

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,

回答1:

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();
                }
            }
        }


回答2:

I have been doing this for a long time and found a utility program named SPViews. You point it at the content database and it generates the SQL script to create the views for you. It reads the compressed field to get the columns and generates the script. You can get the columns from there.

jd