Condividi tramite


Document Information Panel cannot open the form

Supposed that you create a Site Content Type and add a lookup field column to it. You then associate the Content Type to a document library and create a document based on this new Conent Type. When saving the document, you chose a value in the lookup field via the Document Information Panel (DIP) in Word. After this item gets copied/moved (via the SiteManager.aspx functionality for example), the DIP will not show the correct data in the lookup list. If more than one Lookup List is specified, the DIP will fail to render at all and will throw an error:

 Document Information Panel cannot open the form. To fix this problem, contact your system administrator.
Form template: https://servername/site/form.xsn
The following DataObject either cannot be created or cannot be initialized: list_G-U-I-D
Document Information Panel cannot add the following object to the DataObjects collection: list_G-U-I-D
list_G-U-I-D could not be added to the DataObjects collection.
The following item already exists in the collection: list_G-U-I-D

The reason for this is that the DIP expects that the SPField.LookupList property will be enclosed in curly braces { } . On PRIME import (STSADM import or SiteManager.aspx or Content Deployment), these braces get removed and overwrite the Field in the destination list.

As an example, we essentially replace:

 <Field Type="Lookup" DisplayName="LanguageLookup" Required="FALSE" List="{ff74647c-047d-4747-9fcb-397a3dbb2b3a}" ...

with:

 <Field Type="Lookup" DisplayName="LanguageLookup" Required="FALSE" List="ff74647c-047d-4747-9fcb-397a3dbb2b3a" ...

This later causes problems with the Document Information Panel (DIP) when editing from Word as it expects the GUID to be in brackets. Below is a workaround sample code for fixing the invalid GUIDs for the lookup fields by adding the curly braces "{", "}" :

 using (SPSite ms = new SPSite("https://your-server-name"))
using (SPWeb mw = ms.OpenWeb()) {
  try {
    SPList ml = mw.Lists["Document-Library-Name"];
    SPField mf = ml.Fields[new Guid("guid-of-lookup-field")];
    XmlTextReader xr = new XmlTextReader(new StringReader(mf.SchemaXml));
    XmlDocument xd = new XmlDocument();
    XmlNode xn = xd.ReadNode(xr);
    string s = xn.Attributes["List"].Value;
    s = "{" + s + "}"; xn.Attributes["List"].Value = s;
    mf.SchemaXml = xn.OuterXml; mf.Update();
  }
  catch (Exception ex) {
    Console.WriteLine(ex.ToString());
  } }

It may also be needed in some cases that a document is checked in and out on the document library for the above workaround to work:

 using (SPSite site = new SPSite("https://your-server-name"))
using (using SPWeb web = site.OpenWeb()) {
  SPList list = web.Lists["Document-Library-Name"];
  SPListItem item = list.Items[0]; // use the first item
  SPFile file = item.File;
  try {
    file.CheckOut();
    Console.ReadLine();
    file.UndoCheckOut();
    Console.WriteLine("Item checked out and discard checked out");
  }
  catch (Exception e) {
    Console.WriteLine(e.Message);
    throw;
  } }