//used in console apps /// <summary> /// Creates an ClientContext for the SharePoint Uri based on Authentication USer information /// </summary> /// <returns>A ClientContext instance</returns> public static ClientContext CreateSharePointContext(this SharePointContextProvider context, Uri webUrl, SharePointAuthenticationInfo authenticationInfo) { var clientContext = new ClientContext(webUrl); if (authenticationInfo.mode == SharePointMode.OnPremise) { NetworkCredential credentials = new NetworkCredential(authenticationInfo.userName, authenticationInfo.password); clientContext.Credentials = credentials; } else if (authenticationInfo.mode == SharePointMode.Cloud) { SecureString passWord = new SecureString(); foreach (char c in authenticationInfo.password.ToCharArray()) passWord.AppendChar(c); clientContext.Credentials = new SharePointOnlineCredentials(authenticationInfo.userName, passWord); } else { throw new ArgumentException("SharePoint authentication information is invalid!"); } return clientContext; }
//used in console apps /// <summary> /// Creates an ClientContext for the SharePoint Uri based on Authentication USer information /// </summary> /// <returns>A ClientContext instance</returns> public static ClientContext CreateSharePointContext(this SharePointContextProvider context, Uri webUrl, SharePointAuthenticationInfo authenticationInfo) { var clientContext = new ClientContext(webUrl); if (authenticationInfo.mode == SharePointMode.OnPremise) { NetworkCredential credentials = new NetworkCredential(authenticationInfo.userName, authenticationInfo.password); clientContext.Credentials = credentials; } else if (authenticationInfo.mode == SharePointMode.Cloud) { SecureString passWord = new SecureString(); foreach (char c in authenticationInfo.password.ToCharArray()) { passWord.AppendChar(c); } clientContext.Credentials = new SharePointOnlineCredentials(authenticationInfo.userName, passWord); } else { throw new ArgumentException("SharePoint authentication information is invalid!"); } return(clientContext); }
static void Main(string[] args) { solutionPath = ConfigurationManager.AppSettings["WorkflowTemplatePath"]; workflowFeature = new Guid(ConfigurationManager.AppSettings["WorkflowFeatureId"]); workflowUserSolutionId = new Guid(ConfigurationManager.AppSettings["WorkflowSolutionId"]); Uri webUrl = new Uri(ConfigurationManager.AppSettings["SharePointUrl"]); SharePointAuthenticationInfo authenticationInfo = new SharePointAuthenticationInfo() { userName = ConfigurationManager.AppSettings["UserName"], password = ConfigurationManager.AppSettings["Password"], mode = (SharePointMode)Enum.Parse(typeof(SharePointMode), ConfigurationManager.AppSettings["SharePointMode"]) }; using (ClientContext context = SharePointContextProvider.Current.CreateSharePointContext(webUrl, authenticationInfo)) { ProvisionWorkflow(context); RemoveWorkflow(context); } }
static void Main(string[] args) { solutionPath = ConfigurationManager.AppSettings["WorkflowTemplatePath"]; workflowFeature = new Guid(ConfigurationManager.AppSettings["WorkflowFeatureId"]); workflowUserSolutionId = new Guid(ConfigurationManager.AppSettings["WorkflowSolutionId"]); Uri webUrl = new Uri(ConfigurationManager.AppSettings["SharePointUrl"]); SharePointAuthenticationInfo authenticationInfo = new SharePointAuthenticationInfo() { userName = ConfigurationManager.AppSettings["UserName"], password = ConfigurationManager.AppSettings["Password"], mode = (SharePointMode)Enum.Parse(typeof(SharePointMode), ConfigurationManager.AppSettings["SharePointMode"]) }; using (ClientContext context = SharePointContextProvider.Current.CreateSharePointContext(webUrl, authenticationInfo)) { ProvisionWorkflow(context); RemoveWorkflow(context); } }