Trying to change a number of promoted fields via an update console app - InfoPath Dev
in

InfoPath Dev

Trying to change a number of promoted fields via an update console app

Last post 07-02-2010 03:31 AM by chris leate. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-01-2010 02:17 AM

    Trying to change a number of promoted fields via an update console app

    Hi Guys and Gals,
    I've found myself in a situation where I need to change some of the promoted fields in an infopath library. I've started writing a simple console app in order to change these fields. According to a number of blog articles I've read it is possible to change the promoted fields in the sharepoint database and the created by field with c#. I've managed to change the created date programmatically with code that looks a bit like this:

        SPSite site = new SPSite("http://MyWebsiteURL");
        SPWeb web = site.OpenWeb();
        web.AllowUnsafeUpdates = true;
        SPList list = web.Lists["MyLibraryName"];
        SPListItemCollection collection = list.Items;
     
        SPUser user = web.EnsureUser("LoginNameOfUserToChangeTo");
        foreach (SPListItem item in collection )
                   {                              

        
                                  //1073741823;#System Account   //User name values are in this format ID;#Login Name
                                  string AccountIDString = user.ID + ";#" + user.Name; //Create in same format

         SPSecurity.RunWithElevatedPrivileges(delegate()
                                     {

                                             item["Created"] = new DateTime(2008, 5, 7);
                                             item["Author"] = AccountIDString;
     
                                            item.Update();  //Update the item
                                     }

    );

         
        }

        // Update list then site
        list.Update();
        web.Update();

    Strangely enough the code runs fine and throws no errors but most properties will not update. The only indexed column which changes is the Created field which contains the date the document was created. I've tried updating the promoted fields from the InfoPath form itself but no joy. I've tried referencing the item as item[Created By] etc.

    I can open the library in datasheet view but it shows as read-only. I've even given myself full control over the library, still nada. I can even write the values of the fields with Console.Write. The update, however doesn't work. strangely enough also, I am able to update the list and give the library a new name programmatically, I can even rename the site programmatically using the code above but I can't  change the promoted properties or the created by field. Any ideas?

     

  • 07-01-2010 04:17 AM In reply to

    Re: Trying to change a number of promoted fields via an update console app

    You appear to be able to change the item[edited] field too, which is the promoted as field Modified By 

  • 07-01-2010 04:35 AM In reply to

    Re: Trying to change a number of promoted fields via an update console app

  • 07-02-2010 03:31 AM In reply to

    Re: Trying to change a number of promoted fields via an update console app

    There's no way of achieving this without manually editing it in the sharepoint database. I've done this now
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.