Infopath中,自己编写的ActiveX控件,为何不能绑定数据到XML属性节点
2007-11-07 09:47
369 查看
转自:http://www.mcse.ms/message1299834.html&highlight=InfopathControl.savestate
I've been recently dealing with this same issue and here's the resolution
I've come to:
1. You can ONLY use Integers, Longs and Strings to represent your data in
InfoPath. I tried stdOLE.Picture, Variant, Byte() and they all won't bind by
default (or at all after many hours of recompiling to test). Why you ask?,
InfoPath is storing the data in an XML document file as node data
(<node>datadatadatadata</node>). Most types of data are using illegal
characters in this context and utf-8 or iso-8859-1 encoding won't solve the
problem, and I'm not quite sure why.
The simple resolution to storing ANY form of binary data is to Base64 encode
the data and return it as a String. Just to be fair here, after talking with
Microsoft about this using Visual Studio .NET and creating a
custom InfoPath form with the SDK should allow for binary data, however the
reason some of us are using ActiveX controls for data representation is
because not everyone working with InfoPath is a programmer, which is what is
expected when using .NET. This process is futher complicated by having to
create custom data schemas for InfoPath in VS .NET. Again, the simple
resolution to storing ANY form of binary data is to Base64 encode the data
and return it as a String.
2. Even though some of the examples lead you to believe that you can have
your own Public Property names, InfoPath's default schema only recognizes
ENABLED and VALUE (just as the examples show, but don't clearly state this as
a condition), so you may have to adjust your code to expose those names, or
use the InfoPath SDK and extend the default schema to accomodate your public
properties, for which I haven't seen any faq's or examples.
One more thing I forgot to mention, you must use the StrConv() function to
convert to and from Unicode data for your string value. Again the reason for
this is you're dealing with XML node data. See example below.
Public Property Get Value() As String 'Needs to be called Value, data needs to be String 'Ignore all Errors or InfoPath will die an Automation Exception death
On Error Resume Next
Set m_oSig = New cSigControl
If m_Signature.Handle Then 'Convert our STDOLE Picture to Base64 encoded string.'Then convert the Base64 string to UniCode and return the value.
Value = StrConv(m_oSig.SetStreamPicture(m_Signature), vbUnicode)
End If
Set m_oSig = Nothing
End Property
Public Property Let Value(vData As String) 'Needs to be called Value, data needs to be string 'Ignore all Errors or InfoPath will die an Automation Exception death
On Error Resume Next
Set m_oSig = New cSigControl
'Convert the incoming string from Unicode, then decode the Base64 encoding
'Stream the Base64 encoding back to STDOLE Picture.
'GetStreamPricture will return true if succussfully converted Base64
stream to IPicture.
If m_oSig.GetStreamPicture(StrConv(vData, vbFromUnicode)) Then
Set m_Signature = m_oSig.UserSignature 'Double checking for validity
If Not m_Signature Is Nothing Then
Set UserControl.Picture = m_Signature
Me.SignDocument = False
PropertyChanged "Value"
End If
End If
UserControl_Paint
UserControl.Refresh
Set m_oSig = Nothing
End Property
I've been recently dealing with this same issue and here's the resolution
I've come to:
1. You can ONLY use Integers, Longs and Strings to represent your data in
InfoPath. I tried stdOLE.Picture, Variant, Byte() and they all won't bind by
default (or at all after many hours of recompiling to test). Why you ask?,
InfoPath is storing the data in an XML document file as node data
(<node>datadatadatadata</node>). Most types of data are using illegal
characters in this context and utf-8 or iso-8859-1 encoding won't solve the
problem, and I'm not quite sure why.
The simple resolution to storing ANY form of binary data is to Base64 encode
the data and return it as a String. Just to be fair here, after talking with
Microsoft about this using Visual Studio .NET and creating a
custom InfoPath form with the SDK should allow for binary data, however the
reason some of us are using ActiveX controls for data representation is
because not everyone working with InfoPath is a programmer, which is what is
expected when using .NET. This process is futher complicated by having to
create custom data schemas for InfoPath in VS .NET. Again, the simple
resolution to storing ANY form of binary data is to Base64 encode the data
and return it as a String.
2. Even though some of the examples lead you to believe that you can have
your own Public Property names, InfoPath's default schema only recognizes
ENABLED and VALUE (just as the examples show, but don't clearly state this as
a condition), so you may have to adjust your code to expose those names, or
use the InfoPath SDK and extend the default schema to accomodate your public
properties, for which I haven't seen any faq's or examples.
One more thing I forgot to mention, you must use the StrConv() function to
convert to and from Unicode data for your string value. Again the reason for
this is you're dealing with XML node data. See example below.
Public Property Get Value() As String 'Needs to be called Value, data needs to be String 'Ignore all Errors or InfoPath will die an Automation Exception death
On Error Resume Next
Set m_oSig = New cSigControl
If m_Signature.Handle Then 'Convert our STDOLE Picture to Base64 encoded string.'Then convert the Base64 string to UniCode and return the value.
Value = StrConv(m_oSig.SetStreamPicture(m_Signature), vbUnicode)
End If
Set m_oSig = Nothing
End Property
Public Property Let Value(vData As String) 'Needs to be called Value, data needs to be string 'Ignore all Errors or InfoPath will die an Automation Exception death
On Error Resume Next
Set m_oSig = New cSigControl
'Convert the incoming string from Unicode, then decode the Base64 encoding
'Stream the Base64 encoding back to STDOLE Picture.
'GetStreamPricture will return true if succussfully converted Base64
stream to IPicture.
If m_oSig.GetStreamPicture(StrConv(vData, vbFromUnicode)) Then
Set m_Signature = m_oSig.UserSignature 'Double checking for validity
If Not m_Signature Is Nothing Then
Set UserControl.Picture = m_Signature
Me.SignDocument = False
PropertyChanged "Value"
End If
End If
UserControl_Paint
UserControl.Refresh
Set m_oSig = Nothing
End Property
相关文章推荐
- Infopath中,自己编写的ActiveX控件,为何不能绑定数据到XML属性节点
- 读取Xml文件,创建DataTable,递归循环Xml节点,添加数据到DataTable,绑定到GridView
- 不能在数据绑定的 DataGridView 控件上设置 ColumnCount 属性
- 读取XML的节点属性并绑定到ListBox
- 读取XML的节点属性并绑定到ListBox
- sql遍历xml,遍历节点并遍历节点值,xm节点属性数据转换成表
- 读取XML的节点属性并绑定到ListBox
- 利用KissXML解析xml数据,并对XML节点属性进行修改
- XmlDataSource使用xmlDataSource.Data属性绑定xml数据时,无法使用缓存
- .NET数据访问集锦(二)编写自己的SqlHelper
- C#下 读取xml节点的数据总结 .txt
- WPF: ListBox绑定xml数据
- json数据与JAVA数据的转换 jsonJavaBean.netApache 自己编写了一个工具类,处理页面提交json格式数据到后台,再进行处理成JAVA对象数据 1、DTO:Data T
- [ExtJS5学习笔记]第十六节 Extjs5使用panel新增的ViewModel属性绑定数据
- C# dev GridControl绑定数据不能显示
- 类中自身类的对象不能做自己的数据成员
- xml获取属性节点的值
- 让ListBox的SelectedItems属性支持数据绑定
- VOC数据提取自己需要的类生成XML标签
- 避免 XML 属性?针对元数据的 XML 属性