Showing posts with label Sharepoint 2013. Show all posts
Showing posts with label Sharepoint 2013. Show all posts

Tuesday, May 30, 2017

Sharepoint Designer 2013, XSLT List View Options ribbon option is not showing

Sharepoint Designer 2013, XSLT List View Options ribbon option is not showing


I have an ordinary Wiki Page, also tried making an Article Page.
Once this page is made, I add an XsltListViewWebPart that points to a list, which is fine, this is added from the sharepoint web site page edit.
When I open it up in Sharepoint Designer 2013, and select the XsltListViewWebPart the ribbon does not contain the List View Options listview for me to edit the filters, parameters etc.
What I do notice is, when I add the XsltListViewWebPart from inside the Sharepoint Designer 2013, I see the ribbon section fine. However once I save changes on the page, close it and re-open it, same issue, can't see that ribbon section.

The solution :
Go to Edit web part and select "Miscellaneous" property and click on Server Render checkbox.
then you will able to see that in designer
hope it helps!

Monday, April 17, 2017

List view error: Attempted to use an object that has ceased to exist

List view  error: Attempted to use an object that has ceased to exist



Error Scenario:
In SharePoint, when navigating to a list view page (ex: 'All Items' view), or to a site page (like home page) that contains a list view web part, the page crashes, throwing the following error:

Server Error in '/' Application.

Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED)) 


Root Cause:
The error is thrown because of the resource throttling in that list. The GroupBy is counting & folding too many items causing SharePoint to prevent the SQL server from processing the view query. When checking the number of items in list settings page, it shows it had 18670 items (way above the default list view threshold of 5000).


Solution:
The fix is to enable larger resource throttling for the target web application.
Example: In this case I set to 20000.

From Central Administration site > Manage Web Applications > select target web app > General Settings > Resource Throttling > change List View Threshold > OK

Note: there is a reason of why Microsoft set the default theshold into 5000 which is to avoid getting a performance hit on SQL server by queries on too many items. When you have very large lists or libraries, try to think about alternative approaches to divide the data, such as split into multiple lists, or using folders in case of document libraries.


SQL Deadlocks and the Project Server Queues

SQL Deadlocks and the Project Server Queues


on SQL deadlocks and error messages like the following on a busy server.
System.Data.SqlClient.SqlError: Transaction (Process ID 84) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
You will also see error id 7747 in the application event log.
This can be an issue with systems that are quite stressed and in all cases I have seen relates to the process that selects the queue jobs for processing. It does not break anything as such and no data is lost – but processing of queue jobs is delayed (but as the system is very busy they probably wouldn’t have processed quickly anyway!).
Deadlocks occur when two transactions interact in such a way that one requires a resource that the other has locked, and vice versa. Because neither task can continue until a resource is available and neither resource can be released until a task continues, a deadlock state exists. SQL Server selects one of the transactions as the victim and ends it – and posts the above error.  See the SQL Server Books Online for more details.
In Project Server 2007 you can monitor activity using perfmon, and the counters include SQL retries per minute for both the Project and Timesheet queues. You can also modify the queue settings which can reduce the occurrence or behavior of the deadlocks. We don’t have any prescriptive guidance yet on suggested changes, but certainly reducing the number of threads, increasing the polling interval, or increasing the SQL retry intervals would likely reduce the number of deadlocks you see. However, these changes will also reduce the throughput of your queue – particularly when processing light weight jobs. If you see the deadlock behavior at specific time of day only – and want to change queue settings to suit workload you could even use the QueueSystem web service to change the settings (using the SetQueueConfiguration method).
I’m not sure if anyone will really want to micro-manage their queue in this way – or what the overall throughput benefits would be – but the option is there.

Friday, January 27, 2017

SPWeb difference between Users, AllUsers and SiteUsers

SPWeb difference between Users, AllUsers and SiteUsers

In short,
SPWeb.Users : Gets the collection of users that are explicilty added.. These users are not parts of any group they are explicitly added..
SPWeb.SiteUsers: Gets the collection of users that belong to the site collection or a group
SPWeb.AllUsers: Gets the collection of All the users. Basically, AllUsers = SiteUsers + Users
Hope it helps
Oumaima,

Deploying Custom Action to Specific Lists in SharePoint

Deploying Custom Action to Specific Lists in SharePoint


There are times when our customers want a custom action menu for a specific list in SharePoint. The custom action menu must be available when we navigate to a specific list and not be available for other lists.

This article details a method to create a custom action in SharePoint that can be deployed to a specific list.

Here, we do not build the custom action using modules or the SharePoint designer. We are building it via a feature. The custom action is defined and bound to the ribbon on feature activation and removed on feature deactivation.

Let's first understand the requirements here:
  1. When the SharePoint user logs in to a SP site and navigates to a specific list, a custom action (for example, "Validate") must be available for the items of the list.
  2. The custom action must not be available for other lists in the site.
  3. When the user clicks on the custom action, a column in the list (for example, Status) must changed to "validé".
I have a SharePoint document library named "Documents" 


Here, we will create the custom action using a feature.

1. In Visual Studio create a new project and add the following code to the Feature Activated event.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists.TryGetList("Products");
                if (list != null)
                {
                    var actionValidate = list.UserCustomActions.Add();
                    actionValidate.Location = "CommandUI.Ribbon";
                    actionValidate.Rights = SPBasePermissions.ManageLists
                        | SPBasePermissions.CancelCheckout | SPBasePermissions.AddListItems
                        | SPBasePermissions.EditListItems | SPBasePermissions.DeleteListItems
                        | SPBasePermissions.ViewListItems | SPBasePermissions.ApproveItems
                        | SPBasePermissions.OpenItems | SPBasePermissions.ViewVersions
                        | SPBasePermissions.DeleteVersions | SPBasePermissions.CreateAlerts
                        | SPBasePermissions.ViewFormPages | SPBasePermissions.ManagePermissions
                        | SPBasePermissions.ViewUsageData | SPBasePermissions.ManageWeb
                        | SPBasePermissions.AddAndCustomizePages | SPBasePermissions.ApplyThemeAndBorder
                        | SPBasePermissions.ApplyStyleSheets | SPBasePermissions.BrowseDirectories
                        | SPBasePermissions.CreateSSCSite | SPBasePermissions.ViewPages
                        | SPBasePermissions.EnumeratePermissions | SPBasePermissions.BrowseUserInfo
                        | SPBasePermissions.ManageAlerts | SPBasePermissions.UseRemoteAPIs
                        | SPBasePermissions.UseClientIntegration | SPBasePermissions.Open
                        | SPBasePermissions.EditMyUserInfo | SPBasePermissions.CreateGroups
                        | SPBasePermissions.ManagePersonalViews | SPBasePermissions.AddDelPrivateWebParts
                        | SPBasePermissions.UpdatePersonalWebParts;
                    actionValidate.Sequence = 100;
                    actionValidate.Title = "Validation en masse";
                    actionValidate.CommandUIExtension = @"<CommandUIExtension><CommandUIDefinitions>
                    <CommandUIDefinition Location=""Ribbon.Documents.Manage.Controls._children"">
                    <Button Id=""{245CAE99-A250-4E2F-8448-A108ABE688A3}"" Sequence=""100"" TemplateAlias=""o1""
                     Image16by16=""_layouts/Validate/Images/Validate-icon-16.png""
                                      Image32by32=""_layouts/Validate/Images/Validate-icon-32.png""
                    Command=""{A139C8C3-3475-4DAE-92AB-57C49C542D6C}"" CommandType=""General"" LabelText=""Seal Record"" />
                    </CommandUIDefinition>
                    </CommandUIDefinitions>
                    <CommandUIHandlers>
                    <CommandUIHandler Command =""{A139C8C3-3475-4DAE-92AB-57C49C542D6C}"" CommandAction=""Validate();"" />
                    </CommandUIHandlers></CommandUIExtension>";
                    actionValidate.Update();

                    var scriptlink = site.UserCustomActions.Add();
                    scriptlink.Location = "ScriptLink";
                    scriptlink.ScriptSrc = "/_layouts/Validate/JScript1.js";
                    scriptlink.Update();
                }
            }
        }
We are first getting the handle to the list that we want to show the custom action for, and adding a custom action item.

We specify the location of the custom action "CommandUI.Ribbon"; that is, we want the custom action for a document similar to new / edit item).

We specify the rights needed for a user to see this custom action. In this case, the permissions are those available for default contributor settings.

Next we specify the sequence (where in the group, the action must appear). This is especially important if you have more than one custom action. I have noted that this must of the form 100, 200 .... Any other sequence - such as 100, 101.. or 20, 21 and so on seems to fail in a multi-action scenario. The behaviour becomes random after a postback if the sequence is not in multiples of 100.

Next, we specify the title for the action; in our case it is "Validation en masse".

Next, we specify the CommandUIExtenstion. Here we give a GUID to the button (can be obtained from GUID creator utility in Visual Studio) and supply the 16*16 and 32*32 icons for the button. We also specify a GUID for the command handler, that has a corresponding action that calls a JavaScript method to fire when the user clicks on the custom action button. In case of SharePoint 2013, the relative URL to the layouts folder would need to be appended with a "/15/". You can refer to this article for further details.

We conclude by providing the location of the JavaScript file, where the handler method is defined.

2. Next, add the following code to the feature deactivating event:
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists.TryGetList("Products");
                if (list != null)
                {
                    list.UserCustomActions.Clear();
                }
            }  
        }
This is to ensure that when the feature is deactivated, the custom actions in the ribbon are removed too.

3. Next, we must add the images and the JavaScript files we specified in the feature activated handler.

In the Visual Studio project, add a "Mapped folder" to Layouts as shown below and create a subfolder, named Images and add the 2 icon images (relevant to your custom action) to this folder.

Mapped folder

Next add a new JavaScript item to the project folder and name it Jscript1.js. Remember, we provided the same name in Step #1, where we specified the handler file and method name.

4. Now, we need to implement the JavaScript handler. In the js file created in the previous step, add the 2 methods as below.
function Validate() {
    var ctx = SP.ClientContext.get_current();
    var ItemIds = "";
    //get current list id
    var listId = SP.ListOperation.Selection.getSelectedList();
    // get list name
    var web = ctx.get_web();
    var list = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());

    //get all selected list items
    var selectedItems = SP.ListOperation.Selection.getSelectedItems(ctx);

    //collect selected item ids
    for (var i = 0; i < selectedItems.length; i++) {
        ItemIds += selectedItems[i].id + ",";
    }

    var pageUrl = SP.Utilities.Utility.getLayoutsPageUrl('/Validate/Validate.aspx?ids=' + ItemIds + '&listid=' + listId);
    var options = SP.UI.$create_DialogOptions();
    options.width = 250;
    options.height = 100;
    options.url = pageUrl;
    options.dialogReturnValueCallback = Function.createDelegate(null, OnDialogClose);
    SP.UI.ModalDialog.showModalDialog(options);   
}
//called on dialog closed
function OnDialogClose(result, target) {
    //if ok button is clicked in dialog, reload the grid.
    if (result == SP.UI.DialogResult.OK) {
        location.reload(true);
    }
}
Here, we are iterating through the selected items and capturing the ids in an array and calling an application page "Validate.aspx" with the ids as a QueryString paramater. We are also specifying that after the call is done, when control returns back, invoke the "OnDialogClose" method, where we are reloading the base page.

5. Next, let us create the application page "Validate.aspx", where the actual update of the records occurs.

Add a new application page to the mapped layouts folder and add a button to the page. Here is the code of the content in the aspx file.
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/javascript">
    function closeDialog() {
        SP.UI.ModalDialog.commonModalDialogClose(0, 'Cancelled clicked');
    }
    function finisheDialog() {
        SP.UI.ModalDialog.commonModalDialogClose(1, 'Finished operation');
    }
    </script>
    <div style="text-align: center">
        <asp:Button ID="btnConfirm" runat="server" Text="Seal Records" Visible="false"OnClick="btnConfirm_Click" />
        <br /><br />
        <asp:Label ID="lblMessage" runat="server"></asp:Label>
    </div>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Seal Record
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"runat="server" >
Seal Record
</asp:Content>
Use the following code for the code behind of this application page.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.WebControls;

namespace Validation.Layouts.Validate
{
    public partial class DocumentRecord : LayoutsPageBase
    {
       
        private List<int> ItemIDs
        {
            get
            {
                string ids = HttpUtility.UrlDecode(Request.QueryString["ids"]).Trim(new[] { ',' });
                return ids.Split(new[] { ',' })
                    .Select(strId => Convert.ToInt32(strId))
                    .ToList();
            }
        }

        List<string> values = new List<string>();
        protected void Page_Load(object sender, EventArgs e)
        {          
          btnConfirm.Visible = true;          
        }

        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                using (SPSite oSite = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb oWeb = oSite.OpenWeb())
                    {
                        oWeb.AllowUnsafeUpdates = true;
                        SPList oList = oWeb.Lists.TryGetList("Documents");
                        bool pageRefresh = false;
                        if (ItemIDs.Count > 0)
                        {
                                StringBuilder strMessage = new StringBuilder();
                                foreach (int item in ItemIDs)
                                {
                                    SPListItem ListItem = oList.GetItemById(item);
                                    if (ListItem != null)
                                    {
                                        if (ListItem["Status"] != null)
                                        {
                                            string docStatus = ListItem["Status"].ToString();
                                            //Check if selected item is locked
                                            if (docStatus.Equals("Open")
                                            {
                                                    ListItem["Status"] = "Validé";                                                       
                                                    ListItem["Editor"] = SPContext.Current.Web.CurrentUser;
                                                    ListItem.Update();
                                                    pageRefresh = true;                                                    
                                            }
                                        }
                                    }
                                }
                                string script = string.Empty;                                  

                                if (pageRefresh)
                                {
                                    //If any one record is processed, refresh the page
                                    ScriptManager.RegisterStartupScript(this, GetType(), "Message""finisheDialog();"true);
                                }
                               
                        }
                        oWeb.AllowUnsafeUpdates = false;
                    }
                }              
            }
            catch (Exception ex)
            {
               
            }
        }

    }
}

Here, on click of the button "btnConfirm", we are iterating the list for each of the selected records and updating the status to "Validé". Once all the records are updated, we are passing back to JavaScript to refresh the page.

Here are some screenshots of the preceding solution. The main focus here is to register the custom action through the feature. I found this to be one effective way to associate a custom action to one specific list and not to all lists / libraries in general. Hope someone finds this useful.




That it !

Oumaima,

Sharepoint Designer 2013, XSLT List View Options ribbon option is not showing

Sharepoint Designer 2013, XSLT List View Options ribbon option is not showing I have an ordinary Wiki Page, also tried making an Article...