More in this section
Forums / Developing with Sitefinity / Renaming ILibrary programatically

Renaming ILibrary programatically

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
3 posts, 0 answered
  1. Pavel N
    Pavel N avatar
    2 posts
    Registered:
    22 Mar 2010
    06 Aug 2010
    Link to this post
    Hello,

    I'm trying to rename a library progrmatically.

    I'm doing this:
    LibraryManager libMgr = new LibraryManager();
    ILibrary lib = libMgr.GetLibrary(oldLibraryName);
             
    if (lib != null)
    {           
       lib.Name = newLibraryName;                
       libMgr.SaveLibrary(lib);
    }

    and get an exception:

    You cannot change a value of an object that is not in transaction.


    What am I doing wrong?

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    08 Aug 2010
    Link to this post
    Hello Pavel N,

    Inside the if loop get the library by its ID and rename it. Below is a sample code

    var m = new LibraryManager("Libraries");
    var lib = m.GetLibrary("CurrentLibraryName");
    if (lib != null)
    {
        var libInTransaction = m.GetLibrary(lib.ID);
        libInTransaction.Name = "ChangedName";
        m.SaveLibrary(libInTransaction);
    }


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Pavel N
    Pavel N avatar
    2 posts
    Registered:
    22 Mar 2010
    09 Aug 2010
    Link to this post
    Thank you very much!
Register for webinar
3 posts, 0 answered