Programmatically Adding Profiles to Document Trees

Discussions concerning general integration topics.

Moderator: Phil Barton

Post Reply
timothymeyer16
Posts: 37
Joined: Mon Jun 14, 2021 9:47 am

Programmatically Adding Profiles to Document Trees

Post by timothymeyer16 »

Good Afternoon,

I'm working on a script to clean up our document tree profiles.

The code below shows how I am able to pull the profiles associated to an IDocumentTree item.

However, I can not seem to set or add or remove profiles to said IDocumentTree instance.

Is this possible?

Code: Select all

foreach (IDocumentTreeInfo treeInfo in DocumentManager.DocumentTrees)
                {

                    IDocumentTree documentTree = DocumentManager.GetDocumentTree(treeInfo);
                    Console.WriteLine(treeInfo.Name);
                    foreach (IProfileInfo profile in documentTree.Profiles)
                    {
                        Console.WriteLine(profile);
                    }
                    Console.ReadLine();

                }
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Programmatically Adding Profiles to Document Trees

Post by BobRichards »

This is been passed to R&D. I will report any information when I get it.
Bob Richards, Senior Software Developer, SoftPro
timothymeyer16
Posts: 37
Joined: Mon Jun 14, 2021 9:47 am

Re: Programmatically Adding Profiles to Document Trees

Post by timothymeyer16 »

I was able to get something working - Essentially I just treated it like a list and then applied changes:

This is how I reset the profiles

Code: Select all

 IDocumentTree tree = DocumentManager.GetDocumentTree(treeInfo);
tree.Profiles.Clear();
DocumentManager.ApplyChanges(tree);

This is how I added a profile

Code: Select all

foreach (IProfileInfo profileinfo in selectProfiles)
{
	 IDocumentTree tree = DocumentManager.GetDocumentTree(treeInfo);
           if (!tree.Profiles.Contains(profileinfo))
            {
                   tree.Profiles.Add(profileinfo);
                   DocumentManager.ApplyChanges(tree);
             }
}
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Programmatically Adding Profiles to Document Trees

Post by BobRichards »

I'm glad you figured it out and posted an answer for others that run into this problem. :D

Also I'm sorry that I could not help in a timely fashion.
Bob Richards, Senior Software Developer, SoftPro
Post Reply