1

Have created 200 same SharePoint Lists with InfoPath, under different subsites. I want to modify the fields on each list:

From:
Q12014 to Q1Y1
Q22014 to Q2Y1
Q32014 to Q3Y1
Q42014 to Q4Y1
Q12015 to Q1Y2
Q22015 to Q2Y2...

Is there any way instead of going one by one with InfoPath, change the fields and publish, to do it faster?

2
  • Is this a centralized InfoPath form that is being utilized in many places or is the form a template in each library individually? Commented Dec 18, 2014 at 19:00
  • Separate lists, not centralized, in many places.
    – Eugene L
    Commented Dec 18, 2014 at 20:14

2 Answers 2

2

Using CSOM it's possible to complete the operation.

Write a console application to get all subsites of a site collection and get the list from each site. Then get the field collection and get the particular field by name and if it's the required one: update it.

Kindly find the code sample below

class Program
{


    static string Path = "http://Path:8082";
    static void Main(string[] args)
    {

        ChangeListColumns(Path);
        Console.Read();
    }

    public static void ChangeListColumns(string path)
    {

        try
        {
            ClientContext clientContext = new ClientContext(path);
            Web oWebsite = clientContext.Web;
            clientContext.Load(oWebsite, website => website.Webs, website => website.Title);
            clientContext.ExecuteQuery();
            foreach (Web orWebsite in oWebsite.Webs)
            {

                Web oWebsite1 = clientContext.Web;

                List olist = orWebsite.Lists.GetByTitle("ListTitle");
                FieldCollection oFieldCollection = olist.Fields;

                foreach (Field oField in oFieldCollection)
                {
                    if (oField.Title.Equals("oldName"))
                    {
                        oField.Title = "NewName ";
                        oField.Update();
                        olist.Update();
                        ClientContext clientContext1 = new ClientContext(orWebsite.ServerRelativeUrl);
                        clientContext1.Load(olist);
                        clientContext1.ExecuteQuery();
                    }

                }
            }
        }
        catch (Exception ex)
        {

        }


    }
}
1
  • the idea is Ok for 1 field, but this code it wont work with sharepoint online
    – Eugene L
    Commented Dec 19, 2014 at 15:21
1

PowerShell is the go-to tool for this kind of change. You could write a PowerShell script to scan through your sites and lists and match field names you want to change. I don't know how well InfoPath will tolerate the change, you may need to re-publish, and it may break things entirely, so test well and use your test/staging environment if available.

1
  • if i new how to write powershell i wasn going to ask in here for help, dont you think? :)
    – Eugene L
    Commented Dec 19, 2014 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.