GetWebLoginClientContext() public method

Returns a SharePoint on-premises / SharePoint Online ClientContext object. Requires claims based authentication with FedAuth cookie.
public GetWebLoginClientContext ( string siteUrl, System icon = null ) : ClientContext
siteUrl string Site for which the ClientContext object will be instantiated
icon System Optional icon to use for the popup form
return ClientContext
コード例 #1
0
        internal static SPOnlineConnection InstantiateWebloginConnection(Uri url, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, bool skipAdminCheck = false)
        {
            var authManager = new OfficeDevPnP.Core.AuthenticationManager();

            var context = PnPClientContext.ConvertFrom(authManager.GetWebLoginClientContext(url.ToString()), retryCount, retryWait * 1000);

            if (context != null)
            {
                context.RetryCount      = retryCount;
                context.Delay           = retryWait * 1000;
                context.ApplicationName = Properties.Resources.ApplicationName;
                context.RequestTimeout  = requestTimeout;
#if !ONPREMISES
                context.DisableReturnValueCache = true;
#elif SP2016
                context.DisableReturnValueCache = true;
#endif
                var connectionType = ConnectionType.OnPrem;
                if (url.Host.ToUpperInvariant().EndsWith("SHAREPOINT.COM"))
                {
                    connectionType = ConnectionType.O365;
                }
                if (skipAdminCheck == false)
                {
                    if (IsTenantAdminSite(context))
                    {
                        connectionType = ConnectionType.TenantAdmin;
                    }
                }

                return(new SPOnlineConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, null, url.ToString()));
            }
            throw new Exception("Error establishing a connection, context is null");
        }
コード例 #2
0
        private ClientContext GetClientContext()
        {
            AuthenticationManager authManager = new OfficeDevPnP.Core.AuthenticationManager();

            if (clientContext == null)
            {
                return(authManager.GetWebLoginClientContext(SITE_URL));
            }
            else
            {
                return(clientContext);
            }
        }
コード例 #3
0
        private void btnCopy_Click(object sender, RoutedEventArgs e)
        {
            ArrayList arrayList = new ArrayList();

            /// action on source url
            try
            {
                /// get authentication
                var authSourceManager = new OfficeDevPnP.Core.AuthenticationManager();

                var sourceContext = authSourceManager.GetWebLoginClientContext(txtSourceURL.Text);
                Web _web          = sourceContext.Web;
                sourceContext.Load(_web);
                try
                {
                    sourceContext.ExecuteQuery();
                    txtOutput.Text += "Successfully connected to " + txtSourceURL.Text + "\n";
                }
                catch
                {
                    txtOutput.Text += "Failed to connect to " + txtSourceURL.Text + "\n";
                }

                List            _list   = sourceContext.Web.Lists.GetByTitle(txtListName.Text);
                FieldCollection _fields = _list.Fields;
                sourceContext.Load(_list.Fields);
                sourceContext.Load(_fields);
                try
                {
                    sourceContext.ExecuteQuery();
                }
                catch
                {
                    txtOutput.Text += "Faild to get the list " + txtListName.Text + "\n";
                    txtOutput.Text += "Please make sure the list exists \n";
                }
                txtOutput.Text += "Getting " + txtListName.Text + " custom fields.... \n";
                foreach (Field _field in _fields)
                {
                    if (_field.CanBeDeleted)
                    {
                        txtOutput.Text += "---" + _field.Title + "\n";
                        arrayList.Add(_field.SchemaXml);
                    }
                }
                txtOutput.Text += "There are " + arrayList.Count + " custom fields in " + txtListName.Text + "\n";
            }
            catch (Exception ex)
            {
                txtOutput.Text += "Exception happended " + ex.Message + "\n";
            }

            /// actions on destination url
            try
            {
                var authDetinationManager = new OfficeDevPnP.Core.AuthenticationManager();
                var destinationContext    = authDetinationManager.GetWebLoginClientContext(txtDestURL.Text);
                Web destWeb = destinationContext.Web;
                ListCreationInformation creatListInfo = new ListCreationInformation();
                creatListInfo.Title        = txtListName.Text;
                creatListInfo.TemplateType = (int)ListTemplateType.GenericList;
                List newList = destWeb.Lists.Add(creatListInfo);
                if (arrayList.Count > 0)
                {
                    for (int x = 0; x < arrayList.Count; x++)
                    {
                        string currentField = (string)arrayList[x];
                        newList.Fields.AddFieldAsXml(currentField, true, AddFieldOptions.AddToDefaultContentType);
                    }
                }
                try
                {
                    destinationContext.ExecuteQuery();
                    txtOutput.Text += "Successfully created the list with the fields at " + txtDestURL.Text + "\n";
                    txtOutput.Text += " You must manually fix the lookup fields \n";
                }catch (Exception ex)
                {
                    txtOutput.Text += "Failed to create the list \n";
                    txtOutput.Text += ex.Message + "\n";
                }
            }
            catch (Exception ex)
            {
                txtOutput.Text += "Exception happended " + ex.Message + "\n";
            }
        }
コード例 #4
0
        internal static SPOnlineConnection InstantiateWebloginConnection(Uri url, int minimalHealthScore, int retryCount, int retryWait, int requestTimeout, string tenantAdminUrl, bool skipAdminCheck = false)
        {
            var authManager = new OfficeDevPnP.Core.AuthenticationManager();

            var context = PnPClientContext.ConvertFrom(authManager.GetWebLoginClientContext(url.ToString()), retryCount, retryWait * 1000);

            if (context != null)
            {
                context.RetryCount = retryCount;
                context.Delay = retryWait * 1000;
                context.ApplicationName = Properties.Resources.ApplicationName;
                context.RequestTimeout = requestTimeout;
#if !ONPREMISES
                context.DisableReturnValueCache = true;
#elif SP2016
            context.DisableReturnValueCache = true;
#endif
                var connectionType = ConnectionType.OnPrem;
                if (url.Host.ToUpperInvariant().EndsWith("SHAREPOINT.COM"))
                {
                    connectionType = ConnectionType.O365;
                }
                if (skipAdminCheck == false)
                {
                    if (IsTenantAdminSite(context))
                    {
                        connectionType = ConnectionType.TenantAdmin;
                    }
                }

                return new SPOnlineConnection(context, connectionType, minimalHealthScore, retryCount, retryWait, null, url.ToString(), tenantAdminUrl, PnPPSVersionTag);
            }
            throw new Exception("Error establishing a connection, context is null");
        }