Pictures Control Properties - InfoPath Dev
in

InfoPath Dev

Pictures Control Properties

Last post 05-23-2013 10:14 AM by wlfringer. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 04-16-2013 07:07 AM

    Pictures Control Properties

    I am trying to set the default picture for a picture control.  It needs to be set to the users profile drive.  For example:  \\lsasvsrv01\users\username\signature.bmp.  The username variable in the path will be conditional.  Once I have the variable for the username set, I need to set that to the control.  Is this possible?  If so, what would the code look like to accomplish this?

    Here is my form variable name:  thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:frmSignature").text = " " --

    I just put the .text property tag on as an example.

    Thanks! 

     

     

    William L Fringer
    Database Administrator/Systems Integration Specialist
    L&S Associates, A Human Arc Company
    Phone: 800.766.6185, x6605| Fax: 800.698.2877
    3245 Technology Blvd | Lansing, MI 48910
    [email protected] | www.lsaservices.com
  • 04-17-2013 08:37 AM In reply to

    Re: Pictures Control Properties

    Is the picture a link or included in the form? I don't recall if InfoPath 2003 allowed linked pictures. At any rate, if it is a linked picture, can't you just concatenate in the value for the username variable? I guess I am not understanding what you have tried and what the results have been?

    Hilary Stoupa

  • 04-17-2013 09:28 AM In reply to

    Re: Pictures Control Properties

    The Pic control is imbedded in the form.  If I click on it currently, I can browse to the file location.  I am trying to automate this:  I will send you a screen shot.

     

     

    William L Fringer
    Database Administrator/Systems Integration Specialist
    L&S Associates, A Human Arc Company
    Phone: 800.766.6185, x6605| Fax: 800.698.2877
    3245 Technology Blvd | Lansing, MI 48910
    [email protected] | www.lsaservices.com
  • 04-17-2013 09:50 AM In reply to

    Re: Pictures Control Properties

    So - you'll have to get the file from the file system (form will have to be full trust) and encode as Base64. Then set the pic control to the encoded Base64 string.

    Hilary Stoupa

  • 04-17-2013 10:28 AM In reply to

    Re: Pictures Control Properties

    Thanks!

    William L Fringer
    Database Administrator/Systems Integration Specialist
    L&S Associates, A Human Arc Company
    Phone: 800.766.6185, x6605| Fax: 800.698.2877
    3245 Technology Blvd | Lansing, MI 48910
    [email protected] | www.lsaservices.com
  • 05-23-2013 08:42 AM In reply to

    Re: Pictures Control Properties

    Hi Hillary....

    Do you by chance have a code snippett of your solution that I could work from?

     

    Thanks! 

     

    William L Fringer
    Database Administrator/Systems Integration Specialist
    L&S Associates, A Human Arc Company
    Phone: 800.766.6185, x6605| Fax: 800.698.2877
    3245 Technology Blvd | Lansing, MI 48910
    [email protected] | www.lsaservices.com
  • 05-23-2013 08:56 AM In reply to

    Re: Pictures Control Properties

    Hilary Stoupa

  • 05-23-2013 08:57 AM In reply to

    Re: Pictures Control Properties

    Ok...I wrote the code to encode but I receive the following error:

     

    '#PCDATA' is in nil content: <{http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-10-14T02:45:00}frmSignature>.

       at Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode.set_text(String value)
       at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.set_text(String value)
       at DHS2565.DHS2565.btn_CreateNewForm_OnClick(DocActionEvent e) in \\Lsasgm01\gmforms\2565\DHS2565\DHS2565\DHS2565\FormCode.vb:line 75
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

    Here is my code:

    Dim srcBT As Byte()

    Dim dest As String

    Dim srcFile As String = ""

    srcFile = "C:\Documents and Settings\bfadmin\Desktop\signature.bmp"

    Dim sr As New IO.FileStream(srcFile, IO.FileMode.Open)ReDim srcBT(sr.Length)

    sr.Read(srcBT, 0, sr.Length)

    sr.Close()

    dest = System.Convert.ToBase64String(srcBT)

    thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:frmSignature").text = dest

    Thanks a ton! 

     

    William L Fringer
    Database Administrator/Systems Integration Specialist
    L&S Associates, A Human Arc Company
    Phone: 800.766.6185, x6605| Fax: 800.698.2877
    3245 Technology Blvd | Lansing, MI 48910
    [email protected] | www.lsaservices.com
  • 05-23-2013 09:09 AM In reply to

    Re: Pictures Control Properties

    I got it:  Here is my updated code:

    srcFile = "C:\Documents and Settings\bfadmin\Desktop\signature.bmp"

    Dim sr As New IO.FileStream(srcFile, IO.FileMode.Open)ReDim srcBT(sr.Length)

    sr.Read(srcBT, 0, sr.Length)

     

    sr.Close()

    Dim node As Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode = thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:frmSignature")

    RemoveNil(node)

    AddNil(node)

    node.text = ""

    dest = System.Convert.ToBase64String(srcBT)

    thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:frmSignature").text = dest

    I also added the following to my code:

    Public Sub AddNil(ByVal node As Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode)

    If (node Is Nothing) Then

    Return

    End If

    Dim oElement As Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMElement = node

    If (oElement.getAttribute("xsi:nil") Is Nothing) Then

    ' Create xsi:nil attribute with the proper namespace.

    Dim oNil As MSXML2.IXMLDOMAttribute = node.ownerDocument.createNode(MSXML2.DOMNodeType.NODE_ATTRIBUTE, "xsi:nil", "http://www.w3.org/2001/XMLSchema-instance")

    If (oNil Is Nothing) Then

    Return

    End If

    oNil.text = "true"

    If ("" <> node.text) Then

    node.text = ""

    oElement.setAttributeNode(oNil)

    End If

    End If

    End Sub

    Public Sub RemoveNil(ByVal node As Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode)

    If (node Is Nothing) Then

    Return

    End If

    Dim oElement As Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMElement = node

    If (Not (oElement.getAttribute("xsi:nil") Is Nothing)) Then

    oElement.removeAttribute("xsi:nil")

    End If

    End Sub

     

    William L Fringer
    Database Administrator/Systems Integration Specialist
    L&S Associates, A Human Arc Company
    Phone: 800.766.6185, x6605| Fax: 800.698.2877
    3245 Technology Blvd | Lansing, MI 48910
    [email protected] | www.lsaservices.com
  • 05-23-2013 10:14 AM In reply to

    Re: Pictures Control Properties

    For anyone else having this issue, here was final solution:

    Dim srcBT As Byte()

    Dim dest As String

    Dim srcFile As String = ""

    Dim fdlg As System.Windows.Forms.OpenFileDialog = New System.Windows.Forms.OpenFileDialog

    'Check to see if srcFile exists. If it does not, prompt the user to search for the file

    srcFile = "C:\Documents and Settings\bfadmin\Desktop\signature.bmp"

    If System.IO.File.Exists(srcFile) Then

    'Do Nothing

    Else

    With fdlg

    .Title = "Please select file to import:"

    .InitialDirectory = "w:\"

    .Filter = "BMP Files (*.bmp)|*.bmp"

    .FilterIndex = 2

    .RestoreDirectory = True

    .ShowDialog()

    End With

    srcFile = fdlg.FileName

    End If

    Dim sr As New IO.FileStream(srcFile, IO.FileMode.Open)ReDim srcBT(sr.Length)

    sr.Read(srcBT, 0, sr.Length)

     

    sr.Close()

    Dim node As Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode = thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:frmSignature")

    RemoveNil(node)

    AddNil(node)

    node.text = ""

    dest = System.Convert.ToBase64String(srcBT)

    thisXDocument.DOM.selectSingleNode(
    "/dfs:myFields/my:frmSignature").text = dest

    Thanks Hilary for poiting me in the right direction!! 

     

    William L Fringer
    Database Administrator/Systems Integration Specialist
    L&S Associates, A Human Arc Company
    Phone: 800.766.6185, x6605| Fax: 800.698.2877
    3245 Technology Blvd | Lansing, MI 48910
    [email protected] | www.lsaservices.com
Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.