word中非空字段为空
我创建了一个多列自定义字段并将其部署在 SharePoint 中。为了能够使用自定义字段中的字段值,我还部署了一个事件接收器,将自定义字段中的三个值复制到三个单独的常规文本字段。如果这三个文本字段不存在,我会在代码中使用 XML 创建它们。即使字段存在,我也会确保字段具有正确的可见性设置。
在 xml 中创建字段:
string fieldXml = string.Format("<Field ID=\"{0}\" " +
"Type=\"{1}\" " +
"Name=\"{2}\" " +
"StaticName=\"{2}\" " +
"DisplayName=\"{2}\" " +
"Required=\"{3}\" " +
"ShowInEditForm=\"TRUE\" " +
"ShowInNewForm=\"TRUE\" " +
"ShowInDisplayForm=\"TRUE\" " +
"ShowInListSettings=\"TRUE\" " +
"ShowInViewForms=\"TRUE\" " +
"ShowInVersionHistory=\"TRUE\" " +
"ShowInFileDlg=\"TRUE\"" +
"></Field>",
Guid.NewGuid(),
fieldType,
fieldName,
required);
list.Fields.AddFieldAsXml(fieldXml, true, SPAddFieldOptions.Default);
当字段已存在时,确保可见性设置正常:
field.ShowInEditForm = true;
field.ShowInNewForm = true;
field.ShowInDisplayForm = true;
field.ShowInListSettings = true;
field.ShowInViewForms = true;
field.ShowInVersionHistory = true;
field.Update();
list.Update();
创建字段后,我发现无法以编程方式设置 ShowInFileDlg 属性。
问题是,这段代码一直工作得很好,直到我在 MS Word 中打开一个文档,并且三个文本字段都在列表中分配了文本,但在 Word 中它们是空的!
有没有人见过这个,我做错了什么!?
I have created a multicolumn custom field and deployed it in SharePoint. To be able to use the field values from my custom field I also deployed an event receiver to copy the three values from my custom field to three separate regular text fields. If the three text fields do not exist I create them with XML in code. I also make sure the fields have the right visibility settings even if the field exist.
Creating the field in xml:
string fieldXml = string.Format("<Field ID=\"{0}\" " +
"Type=\"{1}\" " +
"Name=\"{2}\" " +
"StaticName=\"{2}\" " +
"DisplayName=\"{2}\" " +
"Required=\"{3}\" " +
"ShowInEditForm=\"TRUE\" " +
"ShowInNewForm=\"TRUE\" " +
"ShowInDisplayForm=\"TRUE\" " +
"ShowInListSettings=\"TRUE\" " +
"ShowInViewForms=\"TRUE\" " +
"ShowInVersionHistory=\"TRUE\" " +
"ShowInFileDlg=\"TRUE\"" +
"></Field>",
Guid.NewGuid(),
fieldType,
fieldName,
required);
list.Fields.AddFieldAsXml(fieldXml, true, SPAddFieldOptions.Default);
Make sure visibility settings OK when the field already exist:
field.ShowInEditForm = true;
field.ShowInNewForm = true;
field.ShowInDisplayForm = true;
field.ShowInListSettings = true;
field.ShowInViewForms = true;
field.ShowInVersionHistory = true;
field.Update();
list.Update();
I found no way of setting the ShowInFileDlg property programmatically once the field was created.
The thing is that this code works great up until I open a document in MS Word and the three text fields all have text assigned in the list but in Word they are empty!
Have anybody seen this before, what am I doing wrong!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了能够在 DIP(Word 文档顶部的文档信息面板)中打开字段,您需要将 SourceId 属性添加到该字段:
SourceID="http://schemas.microsoft.com/sharepoint/v3 "
有关详细信息,请参阅此处 (msdn)。
To be able to open a field in DIP (document information panel at the top in word documents) you need to add the SourceId property to the field:
SourceID="http://schemas.microsoft.com/sharepoint/v3"
For more information see here (msdn).