/// <summary>
        /// Checkout document
        /// </summary>
        /// <param name="localCheckout">Whether document should be checked out locally or on the server side</param>
        /// <returns>
        /// Whether check out process has completed successfully
        /// </returns>
        public bool CheckOut(bool localCheckout)
        {
            string documentUrl = StringUtil.EnsurePostfix('/', this.context.Url) + StringUtil.RemovePrefix('/', this.document.FileRef);

            SharepointUtils.LogDebugInfo(this.context, "Checking out file: [" + documentUrl + "]");
            return(this.ListsWebService.CheckOutFile(documentUrl, localCheckout ? "true" : "false", string.Empty));
        }
        protected void advancedSearchBtn_Click(object sender, EventArgs e)
        {
            advancedSearchBtn.Text          = "»&nbsp;" + Translate.Text(UIMessages.AdvancedSearch);
            advancedSearchSitesPane.Visible = !advancedSearchSitesPane.Visible;
            advancedSearchListsPane.Visible = !advancedSearchListsPane.Visible;

            if (advancedSearchSitesPane.Visible)
            {
                advancedSearchBtn.Text = "»&nbsp;" + Translate.Text(UIMessages.AdvancedSearch);
                Server spServer = ObjectModel.Entities.Server.Connect(SpContext);
                try
                {
                    List <System.Web.UI.WebControls.ListItem> webs = new List <System.Web.UI.WebControls.ListItem> {
                        new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllSites), this.Web)
                    };
                    webs.AddRange(spServer.Webs.Select(web => new ListItem(web.Title, web.Path)));
                    if ((webs.Count > 0))
                    {
                        sitesList.DataSource = webs;
                    }
                    sitesList.DataTextField  = "Text";
                    sitesList.DataValueField = "Value";
                    sitesList.DataBind();

                    listsList.DataSource = new[] { new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllLists)) };
                    listsList.DataBind();
                    AttemptNumber = 0;
                }
                catch (WebException ex)
                {
                    sitesList.DataSource = new[] { new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllSites), this.Web) };
                    sitesList.DataBind();

                    listsList.DataSource = new[] { new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllLists)) };
                    listsList.DataBind();

                    errorLbl.Text = Translate.Text(UIMessages.CouldntGetResponseFromSharepointServer);
                    HttpWebResponse webResponse = ex.Response as HttpWebResponse;
                    if ((webResponse != null) && (webResponse.StatusCode == HttpStatusCode.Unauthorized) &&
                        (webResponse.Headers.AllKeys.Contains("WWW-Authenticate")))
                    {
                        errorLbl.Text = Translate.Text(UIMessages.YouDoNotHaveEnoughRights);
                        if (AttemptNumber < 3)
                        {
                            SharepointExtension.WriteAuthenticationResponseBasic(Request, Response);
                            AttemptNumber++;
                        }
                    }
                    this.ShowErrorLabel();
                    return;
                }
                catch (SoapException ex)
                {
                    SharepointUtils.LogDebugInfo(SpContext, "Can't retrieve info for advanced search");
                    return;
                }
            }
        }
        /// <summary>
        /// Check in document
        /// </summary>
        /// <param name="comment">The comment for SharePoint</param>
        /// <param name="checkInType">The check in type. Possible values
        /// A string representation of the values 0, 1 or 2, where 0 = MinorCheckIn, 1 = MajorCheckIn, and 2 = OverwriteCheckIn.</param>
        /// <returns>
        /// Whether check in process has completed successfully
        /// </returns>
        public bool CheckIn([NotNull] string comment, [NotNull] string checkInType)
        {
            Assert.ArgumentNotNull(comment, "comment");
            Assert.ArgumentNotNull(checkInType, "checkInType");

            string documentUrl = StringUtil.EnsurePostfix('/', this.context.Url) + StringUtil.RemovePrefix('/', this.document.FileRef);

            SharepointUtils.LogDebugInfo(this.context, "Checking in file: [" + documentUrl + "]");

            return(this.ListsWebService.CheckInFile(documentUrl, comment, checkInType));
        }
        protected void sitesList_IndexChanged(object sender, EventArgs e)
        {
            List <System.Web.UI.WebControls.ListItem> lists = new List <System.Web.UI.WebControls.ListItem> {
                new System.Web.UI.WebControls.ListItem(Translate.Text(UIMessages.AllLists))
            };

            listsList.DataSource = null;
            listsList.Items.Clear();
            string siteName = sitesList.SelectedValue;

            if (!string.IsNullOrEmpty(siteName) && (sitesList.SelectedIndex > 0))
            {
                Server spServer = ObjectModel.Entities.Server.Connect(SpContext);
                try
                {
                    Web selectedWeb = spServer.Webs.First(web => web.Path == siteName);
                    if (selectedWeb != null)
                    {
                        lists.AddRange(selectedWeb.Lists.Select(list => new ListItem(list.Name, list is ObjectModel.Entities.Lists.List ? "Lists/" + list.Name : list.Name)));
                    }
                }
                catch (WebException ex)
                {
                    HttpWebResponse webResponse = ex.Response as HttpWebResponse;
                    if ((webResponse != null) && (webResponse.StatusCode == HttpStatusCode.Unauthorized) &&
                        (webResponse.Headers.AllKeys.Contains("WWW-Authenticate")))
                    {
                        SharepointExtension.WriteAuthenticationResponseBasic(Request, Response);
                    }
                    return;
                }
                catch (SoapException ex)
                {
                    SharepointUtils.LogDebugInfo(SpContext, "Couldn't retrieve lists for {0} site.\n{1}", siteName, ex.StackTrace);
                    return;
                }
            }
            listsList.DataTextField  = "Text";
            listsList.DataValueField = "Value";
            listsList.DataSource     = lists;
            listsList.DataBind();
        }
Пример #5
0
        protected void Initialize(string serverUrl, ICredentials serverCredentials)
        {
            if (string.IsNullOrEmpty(serverUrl))
            {
                serverUrl = SharepointUtils.CurrentSharepointServer;
            }

            this.Url = serverUrl;
            if (serverCredentials == null)
            {
                serverCredentials = this.GetPredefinedCredentials();
                if (serverCredentials == null)
                {
                    serverCredentials = CredentialCache.DefaultNetworkCredentials;
                    this.Credentials  = serverCredentials;
                    SharepointUtils.LogDebugInfo(this, "Using DefaultNetworkCredentials");
                }
            }

            this.Credentials = serverCredentials;
            this.InitConfiguration();
        }
Пример #6
0
        /// <summary>Creates context.</summary>
        /// <param name="sharepointServer">The SharePoint server.</param>
        /// <param name="web">The web.</param>
        /// <param name="predefinedContext">The predefined context.</param>
        /// <param name="credentials">The credentials.</param>
        /// <param name="connectionConfiguration">The connection configuration.</param>
        /// <returns>The <see cref="SpContext"/>.</returns>
        protected virtual SpContext CreateContext(string sharepointServer, string web, string predefinedContext, ICredentials credentials = null, string connectionConfiguration = null)
        {
            var context = new SpContext
            {
                Url                     = !string.IsNullOrEmpty(sharepointServer) ? sharepointServer : SharepointUtils.CurrentSharepointServer,
                Credentials             = credentials,
                ConnectionConfiguration = connectionConfiguration
            };

            if (!string.IsNullOrEmpty(context.ConnectionConfiguration) && context.Credentials != null)
            {
                return(context);
            }

            ServerEntry serverEntry = this.GetServerEntry(StringUtil.EnsurePostfix('/', sharepointServer) + StringUtil.RemovePrefix('/', web), predefinedContext);

            if (serverEntry != null)
            {
                if (string.IsNullOrEmpty(context.ConnectionConfiguration))
                {
                    context.ConnectionConfiguration = serverEntry.ConnectionConfiguration;
                }

                if (context.Credentials == null)
                {
                    context.Credentials = serverEntry.Credentials;
                }
            }

            if (context.Credentials == null)
            {
                context.Credentials = this.DefaultCredentials;
                SharepointUtils.LogDebugInfo(context, "Using DefaultNetworkCredentials");
            }

            return(context);
        }