转自: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


posted on 2007-11-07 09:47  Dragon-China  阅读(931)  评论(1编辑  收藏  举报