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

耗尽温柔 提交于 2019-12-06 02:38:17

问题


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



来源:https://stackoverflow.com/questions/8988098/how-could-i-find-the-fields-of-a-sharepoint-list-from-database-in-sharepoint-201

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!