Copy an Infopath form in a forms library with another name - InfoPath Dev
in

InfoPath Dev

Copy an Infopath form in a forms library with another name

Last post 11-21-2008 08:22 AM by Frederik Van Lierde. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 11-19-2008 08:49 AM

    Copy an Infopath form in a forms library with another name

     Hi,

    I have a forms Library with some Infopath forms in it. On submitting the form I want to create n # copies of that form in the same Library with different names/ID.

    I can do this by writing a code in a loop

       SPListItem newItem = list.Items.Add();
       newItem ["Title"] = "Newname";
    ....
    ....                
     
    newItem .Update();    

    But this is manually inserting all the field values in my form. Is there a way to just copy an item and save it in the same forms lib without inserting each and every value to the new list item.
    Thanks
    Sourav
  • 11-19-2008 03:45 PM In reply to

    Re: Copy an Infopath form in a forms library with another name

     Hi,

    I tried to copy a word doc from a doc Lib and it worked fine. Same code gives me an error when I try to copy a Infopath form from forms Lib.

                CopyWebService.Copy myCopyService = new CopyWebService.Copy();
                myCopyService.Credentials = System.Net.CredentialCache.DefaultCredentials;

                string copySource = "http://as73mossdev01:37638/Survey Requests and Reports/Form2.xml";
                string[] copyDest = { "http://as73mossdev01:37638/TestFormsLib/Form2.xml" };

                CopyWebService.FieldInformation myFieldInfo = new CopyWebService.FieldInformation();
                CopyWebService.FieldInformation[] myFieldInfoArray = { myFieldInfo };
                byte[] myByteArray;

                uint myGetUint = myCopyService.GetItem(copySource, out myFieldInfoArray, out myByteArray);

                CopyWebService.CopyResult myCopyResult1 = new CopyWebService.CopyResult();
                CopyWebService.CopyResult myCopyResult2 = new CopyWebService.CopyResult();
                CopyWebService.CopyResult[] myCopyResultArray = { myCopyResult1, myCopyResult2 };

                //Copy the item in a target Lib
                uint myCopyUint = myCopyService.CopyIntoItems(copySource, copyDest, myFieldInfoArray, myByteArray, out myCopyResultArray);

     This code works fine for word doc but gives me a soap exception at myCopyService.GetItem.

    Thanks
    Sourav
  • 11-20-2008 08:55 AM In reply to

    Re: Copy an Infopath form in a forms library with another name

     It worked thanks !!

    Thanks
    Sourav
  • 11-21-2008 08:22 AM In reply to

    Re: Copy an Infopath form in a forms library with another name

    An alternative without WebServices and less code

     Just adapt the fc.Filename.SetStringValue to the correct value

    public void FormEvents_Submit(object sender, SubmitEventArgs e)
            {
                try
                {
                    FileSubmitConnection fc = (FileSubmitConnection)DataConnections["SharePoint Library Submit"];
                    for (int i = 0; i < 5; i++)
                    {
                        fc.Filename.SetStringValue("Form_" + i.ToString());
                        fc.Execute();
                    }
                    e.CancelableArgs.Cancel=false;
                }
                catch
                {
                    e.CancelableArgs.Cancel = true;
                }
       
            }

    Frederik Van Lierde
    Blue InfoPath Blog  ¦  SilverSands Associate  ¦  Do you follow me already?  ¦  We work smart, not hard


    If this article was helpfull, don't forget to rate it, tnx!
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.