Passing ItemMetadata from code without SharePoint - InfoPath Dev
in

InfoPath Dev

Passing ItemMetadata from code without SharePoint

Last post 12-08-2008 01:13 AM by bosjaH. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 12-05-2008 06:45 AM

    • bosjaH
    • Not Ranked
      Male
    • Joined on 12-05-2008
    • Posts 3

    Passing ItemMetadata from code without SharePoint

    First things first, Hello everyone.

    On to business.
    I have a InfoPath form with ItemMetadata added as a secondary data connection. What I'm trying to do is manipulate the embedded ItemMetadata file and then email the form.
    What I'm doing to accomplish this is extract the .xsn, change the values in the ItemMetadata file contained within and recompress it.

    My problem is that the changes I made to the ItemMetadata file are not shown in the InfoPath form, it still shows the data that was in the ItemMetadata.xml when I added the data connection.

    I've allready tried a million things but I just can't figure out why or where it keeps the data it shows. I figured, change the embedded resource and InfoPath will use the new data. I've looked at all the other files contained in the xsn but the data it actually shows is nowhere to be found. I also tried renaming the folder that keeps the original form, but that didn't change a thing.

    Any help would be greatly appreciated.

  • 12-05-2008 10:54 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Passing ItemMetadata from code without SharePoint

    Hello Welcome to the Forums,

    Are you adding the data or changing the schema of your secondary xml file? If you modify or adding the data for those nodes it will reflect when your data connection is automatically retrieve data when form is opened checkbox is checked. Otherwise your changes will not reflect on your InfoPath form.

    If you want to modify the schema structure then you have to modify the Data connection once again with secondary xml to get update the schema in your InfoPath form.

  • 12-07-2008 04:06 AM In reply to

    • bosjaH
    • Not Ranked
      Male
    • Joined on 12-05-2008
    • Posts 3

    Re: Passing ItemMetadata from code without SharePoint

    I'm only adding (actually replacing) the data. I don't touch the schema. The "automatically receive data" option is also checked.

    The old of ItemMetadata: (The one I used to create the data connection)
    <?xml version="1.0" encoding="UTF-8"?>
    <z:row xmlns:z="#RowsetSchema" ows_localeID="1033" ows_workflowInstanceID="b18a43e5-1608-463f-94b5-6c5adf220f65" ows_processID="c64729d9-e64c-4f04-9447-56711f0b71f8" ows_activityType="ApproveActivity" ows_exampleData="false" ows_taskID="c64729d9-e64c-4f04-9447-56711f0b71f8" />

     The new ItemMetadata: (The one I replace it with in code)
    <?xml version="1.0" encoding="UTF-8"?>
    <z:row xmlns:z="#RowsetSchema" ows_localeID="1033" ows_workflowInstanceID="8981ff02-477e-4142-b744-0d1014d14d8e" ows_processID="4667d3e9-8148-42f3-a14f-5f629ea8c81b" ows_activityType="Review" ows_exampleData="false" ows_taskID="7b889753-76ed-4225-90c6-0bdfd5b74035" />

    I have a textfield bound to ows_activityType but when I open the processed xsn it still shows "ApproveActivity", not "Review" as I was hoping/expecting.

     

  • 12-08-2008 12:37 AM In reply to

    Re: Passing ItemMetadata from code without SharePoint

    Hi,

    Can you place the code how you are replacing the data.

     

    Swathip
    www.ggktech.com
  • 12-08-2008 01:13 AM In reply to

    • bosjaH
    • Not Ranked
      Male
    • Joined on 12-05-2008
    • Posts 3

    Re: Passing ItemMetadata from code without SharePoint

     public byte[] ReplaceItemMetadata(string itemMetadata, byte[] infopathTemplate)
    {
                string tempFolder = @"C:\Temp\";
                string extractFolder = tempFolder + Guid.NewGuid().ToString() + @"\";

                // Extract
                CabLib.Extract extractor = new CabLib.Extract();
                MemoryStream xsn = new MemoryStream(infopathTemplate);
                extractor.ExtractStream(xsn, extractFolder);
                xsn.Dispose();
                xsn = null;

                // Replace ItemMetadata
                File.WriteAllText(extractFolder + "ItemMetadata", itemMetadata);

                // Recompress
                //CabLib.Compress compressor = new CabLib.Compress();
                //compressor.CompressFolder(extractFolder, tempFolder + "form.xsn", "*", true, 0);
                string directives = Properties.Resources.directives;
                directives = directives.Replace("<<folder>>", extractFolder);
                directives = directives.Replace("<<tempfolder>>", tempFolder);
                File.WriteAllText(tempFolder + "directives.txt", directives);
                Process.Start("makecab.exe", "/f " + tempFolder + "directives.txt");

                // Convert to byte[]
                byte[] form = File.ReadAllBytes(tempFolder + "Form.xsn");

                // Delete temporary files
                Directory.Delete(extractFolder, true);
                File.Delete(tempFolder + "Form.xsn");

                return form;
    }

    I used CabLib for extracting/compressing the file. Tried again this weekend directly using makecab.exe but that didn't help either.

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