csharp 创建一个SDL Tridion用户trhough CoreService。假设将Tridion核心服务客户端DLL配置为app.config

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 创建一个SDL Tridion用户trhough CoreService。假设将Tridion核心服务客户端DLL配置为app.config相关的知识,希望对你有一定的参考价值。

using System;
using System.ServiceModel;
using Tridion.ContentManager.CoreService.Client;

namespace CoreServiceSandbox
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var client = new CoreServiceClient("basicHttp_2013");
            try
            {
                Console.WriteLine("The current user is {0}\n", client.GetCurrentUser());

                UserData user = client.GetDefaultData(ItemType.User, null, new ReadOptions()) as UserData;
                Console.Write("Username (domain\\username): ");
                user.Title = Console.ReadLine();
                
                Console.Write("Full name: ");
                user.Description = Console.ReadLine();

                Console.Write("Is Tridion administrator: ");
                user.Privileges= ("yes".Equals(Console.ReadLine()) ? 1 : 0);

                Console.WriteLine("\nCreating user...");
                user = client.Create(user, new ReadOptions()) as UserData;
                Console.WriteLine("Created user {0}\n  Username {1}\n  Description {2}\n  Privleges {3}", user.Id, user.Title, user.Description, user.Privileges);
            }
            catch (FaultException<CoreServiceFault> e)
            {
                Console.WriteLine("Error; Core Service said: {0}; {1} ", e.Detail.ErrorCode, string.Join(", ", e.Detail.Messages));
            }
            catch (CommunicationException e)
            {
                Console.WriteLine("Error; Could not connect to the Core Service\n {0}\n {1}", e.Message, e.InnerException);
                client.Abort(); //The channel is aborted and the resources released.
            }
            catch (TimeoutException e)
            {
                Console.WriteLine("Error; Could not connect to the Core Service\n {0}\n {1}", e.Message, e.InnerException);
                client.Abort(); //The channel is aborted and the resources released.
            }
            catch (Exception e)
            {
                Console.WriteLine("Error; Could not connect to the Core Service\n {0}\n {1}", e.Message, e.InnerException);
            }

            Console.WriteLine("\nPress any key to continue...");
            Console.ReadKey();
        }
    }
}

以上是关于csharp 创建一个SDL Tridion用户trhough CoreService。假设将Tridion核心服务客户端DLL配置为app.config的主要内容,如果未能解决你的问题,请参考以下文章

csharp 示例SDL Tridion .Net模板,用于将JSON文件创建为包项,然后将其作为二进制变体发布

csharp 检查TCM URI是否为ECL项。 (SDL Tridion 2013中的ECL API)

csharp 检查TCM URI是否为ECL项。 (SDL Tridion 2013中的ECL API)

ASCX 用户控制 SDL Tridion 2011

csharp 使用SDL Tridion Core Service发布页面。此示例显示如何在没有配置文件和使用B的情况下使用Core Service API

csharp 使用SDL Tridion Core Service发布页面。此示例显示如何在没有配置文件和使用B的情况下使用Core Service API