programmatically refer to ink picture in repeating table - InfoPath Dev
in

InfoPath Dev

programmatically refer to ink picture in repeating table

Last post 03-28-2012 04:19 PM by Hilary Stoupa. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 03-27-2012 04:49 PM

    programmatically refer to ink picture in repeating table

    In a repeating table, I have an ink picture where the user draws. On a button click, I resize their drawing and display it in a picture control. When the user adds a 2nd ink picture, I can't seem to get it to display the resized image. I don't get an error but it doesn't seem to do anything either. I've traced with the debugger and it gets in here and executes everything.  Here's my code:

                string s = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/my:Detail/my:Images/my:InkImage", NamespaceManager).Value;
                Image drawnImage = Base64ToImage(s);
                Image shrunkenImage=ResizeImage(drawnImage, new Size(100, 100));
                s = ImageToBase64(shrunkenImage, System.Drawing.Imaging.ImageFormat.Png);
                DeleteNil(MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/my:Detail/my:Images/my:ShrunkenImage", NamespaceManager));
                MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/my:Detail/my:Images/my:ShrunkenImage", NamespaceManager).SetValue(s);

    Is the XPath of the 2nd image different?

  • 03-27-2012 05:45 PM In reply to

    Re: programmatically refer to ink picture in repeating table

    Let's say my:Images is your repeating node - I figure that would be a good guess....

    You'd want to create an XPathNodeIterator pointing to your repeating my:Images, and then loop through them, using relative paths from there "my:InkImage", "my:ShrunkenImage", etc. Here's an MSDN page with a code sample that should get you started....

    Hilary Stoupa

  • 03-28-2012 03:30 PM In reply to

    Re: programmatically refer to ink picture in repeating table

            public void btnShrink_Clicked(object sender, ClickedEventArgs e)
            {
                XPathNavigator nav = CreateNavigator();
                XPathNodeIterator rows = nav.Select("/dfs:myFields/my:Detail/my:Images", NamespaceManager);
                while (rows.MoveNext())
                {
                    string s = rows.Current.SelectSingleNode("/dfs:myFields/my:Detail/my:Images/my:InkImage", NamespaceManager).Value;
                    Image drawnImage = Base64ToImage(s);
                    Image resizedImage = ResizeImage(drawnImage, new Size(100, 100));
                    s = ImageToBase64(resizedImage, System.Drawing.Imaging.ImageFormat.Png);
                    DeleteNil(rows.Current.SelectSingleNode("/dfs:myFields/my:Detail/my:Images/my:ShrunkenImage", NamespaceManager));
                    rows.Current.SelectSingleNode("/dfs:myFields/my:Detail/my:Images/my:ShrunkenImage", NamespaceManager).SetValue(s);
                }

            }

    I've changed my code like this and it goes thru my while loop twice but it still doesn't display. The first row is ok, but the second one never displays the smaller image.  I get the xpath by clicking the control and going to the datasource and selecting Copy XPath. Do you see a problem? Thx for your help.

  • 03-28-2012 03:49 PM In reply to

    Re: programmatically refer to ink picture in repeating table

    Here's the issue - rows is at my:Images, so you need relative XPath for the rest:

     while (rows.MoveNext())
    {
    string s = rows.Current.SelectSingleNode("my:InkImage", NamespaceManager).Value;
    Image drawnImage = Base64ToImage(s);
    Image resizedImage = ResizeImage(drawnImage, new Size(100, 100));
    s = ImageToBase64(resizedImage, System.Drawing.Imaging.ImageFormat.Png);
    DeleteNil(rows.Current.SelectSingleNode("my:ShrunkenImage", NamespaceManager));
    rows.Current.SelectSingleNode("my:ShrunkenImage", NamespaceManager).SetValue(s);
    }

     

    Hilary Stoupa

  • 03-28-2012 04:09 PM In reply to

    Re: programmatically refer to ink picture in repeating table

    Sure, I get it now. Thanks again.

  • 03-28-2012 04:19 PM In reply to

    Re: programmatically refer to ink picture in repeating table

    You bet, glad you have it working!

    Hilary Stoupa

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.