Last active
September 14, 2015 12:16
-
-
Save jhorsman/9497273 to your computer and use it in GitHub Desktop.
Create an SDL Tridion user trhough CoreService. Assumes having the Tridion Core Service Client DLL config as app.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment