Category Archives: SharePoint

SharePoint – Change default setting of “Send an email invitation”

Hello everyone,

today I want to show you how you can change the default setting of the option “Send an email invitation”. The goal we are aiming for is to give our users a true choice to actively choose to send email invitations or not.

To achieve this we need to edit the AclInv.aspx file on all your SharePoint servers. I recommend to make a backup of the file and save it as something like AclInv.aspx.backup so you can easily revert back to the default settings if you do not like the changes. The changes we will make do not require a reboot of the servers.

SharePoint 2010

This is your default dialog on SharePoint 2010:

To change the default dialog open the AclInv.aspx file located here C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\AclInv.aspx. Now search for chkSendEmail and change Checked=True to Checked=False.

<wssawc:InputFormCheckBox runat="server" id="chkSendEmail" Checked="True" LabelText="<%$Resources:wss,aclver_SendEmailCheckbox%>" ToggleChildren=true>
<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,aclver_SubjectLabel%>" EncodeMethod='HtmlEncode'/>
<wssawc:InputFormTextBox title="<%$Resources:wss,aclver_SubjectTitle%>" class="ms-long" ID="txtEmailSubject" Columns="35" Runat="server" MaxLength=512 OnChange="OnSubjectChanged()" />
<wssawc:InputFormRequiredFieldValidator id="ReqValEmailSubject" runat="server" BreakBefore=true BreakAfter=true EnableClientScript ="false" ControlToValidate="txtEmailSubject"/>
<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,aclver_BodyLabel%>" EncodeMethod='HtmlEncode'/>
<wssawc:InputFormTextBox title="<%$Resources:wss,aclver_BodyTitle%>" class="ms-long" ID="txtEmailBody" Runat="server" TextMode="MultiLine" Columns="40" Rows="8" Cols=64 MaxLength=2000 />
</wssawc:InputFormCheckBox>
<wssawc:InputFormCheckBox runat="server" id="chkSendEmail" Checked="False" LabelText="<%$Resources:wss,aclver_SendEmailCheckbox%>" ToggleChildren=true>
<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,aclver_SubjectLabel%>" EncodeMethod='HtmlEncode'/>
<wssawc:InputFormTextBox title="<%$Resources:wss,aclver_SubjectTitle%>" class="ms-long" ID="txtEmailSubject" Columns="35" Runat="server" MaxLength=512 OnChange="OnSubjectChanged()" />
<wssawc:InputFormRequiredFieldValidator id="ReqValEmailSubject" runat="server" BreakBefore=true BreakAfter=true EnableClientScript ="false" ControlToValidate="txtEmailSubject"/>
<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,aclver_BodyLabel%>" EncodeMethod='HtmlEncode'/>
<wssawc:InputFormTextBox title="<%$Resources:wss,aclver_BodyTitle%>" class="ms-long" ID="txtEmailBody" Runat="server" TextMode="MultiLine" Columns="40" Rows="8" Cols=64 MaxLength=2000 />
</wssawc:InputFormCheckBox>

And after we have saved our changes your dialog will look like this:

That´s it. Your work is done.

SharePoint 2013

This is your default dialog on SharePoint 2013:

To change the default dialog open the AclInv.aspx file located here C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\LAYOUTS\AclInv.aspx. Now search for chkSendEmailv15 and change Checked=True to Checked=False.
Since I did not like the SHOW OPTIONS/HIDE OPTIONS link because I noticed that it confuses inexperienced users more than it is useful to them I commented out some code to remove it as you can see in the below code snippets.

...

function _spBodyOnLoad()
{
txtEmailBodyIsEmpty = InitializeGhostedElement((document.getElementById("<%= txtEmailBody.ClientID %>")), L_EmailBodyGhostedText, formLongInputGhosted, formLongInputNonGhosted, null);
UpdateAddToGroupOrRole();
UpdateWelcomeInheritMessage();
UpdateGivePermissionsHeading();
UpdateSendEmailMessage();
var groupRequiredValidator = (document.getElementById("<%= ReqValGroup.ClientID %>"));
var groupCustomValidator = (document.getElementById("<%= CusValGroup.ClientID %>"));
var txtEmailSubjectRequiredValidator = (document.getElementById("<%= ReqValEmailSubject.ClientID %>"));
if ((groupRequiredValidator != null) || (groupCustomValidator != null) || (txtEmailSubjectRequiredValidator != null))
{
var forceShow = true;
ShowHideMoreOptions(forceShow);
}
RenderSharingInformation();
SetInitialFocus();
}
 
...

<div class="ms-core-form-section">
<asp:PlaceHolder id="PanelShowHideMoreOptions" runat="server">
<wssuc:FoldHyperLink runat="server" LinkTitleWhenFoldClosed="<%$Resources:wss,aclinv_ShowOptions%>" LinkTitleWhenFoldOpened="<%$Resources:wss,aclinv_HideOptions%>" CustomClientClick = "ShowHideMoreOptions();" />
</asp:PlaceHolder>
</div>
<!-- More Options section is initially hidden; ShowHideMoreOptions controls the display of this div when link clicked -->
<div class="ms-core-form-section">
<div id="divMoreOptions" style="display:none;">
<asp:PlaceHolder id="PanelSendEmail" runat="server" visible="false">
<div class="ms-core-form-subsection">
<asp:CheckBox runat="server" id="chkSendEmailv15" Checked="true" class = "ms-aclinv-checkbox" OnClick="UpdateSendEmailMessage()"/>
<label for=<%SPHttpUtility.WriteAddQuote(SPHttpUtility.NoEncode(chkSendEmailv15.ClientID),this.Page);%>>
<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,aclinv_SendEmailCheckboxv15%>" EncodeMethod='HtmlEncode'/>
</label>
<div id="divSendEmailOptions" style="display:none";>
<div class="ms-aclInv-emailOptions-heading"><SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,aclver_SubjectLabelv15%>" EncodeMethod='HtmlEncode'/></div>
<wssawc:InputFormTextBox title="<%$Resources:wss,aclver_SubjectTitle%>" CssClass="ms-fullWidth" ID="txtEmailSubject" Columns="35" Runat="server" MaxLength=512 OnChange="OnSubjectChanged()" />
<wssawc:InputFormRequiredFieldValidator id="ReqValEmailSubject" runat="server" CssClass="ms-error" BreakBefore="false" EnableClientScript ="false" ControlToValidate="txtEmailSubject"/>
</div>
</div>

...
...

function _spBodyOnLoad()
{
txtEmailBodyIsEmpty = InitializeGhostedElement((document.getElementById("<%= txtEmailBody.ClientID %>")), L_EmailBodyGhostedText, formLongInputGhosted, formLongInputNonGhosted, null);
UpdateAddToGroupOrRole();
UpdateWelcomeInheritMessage();
UpdateGivePermissionsHeading();
UpdateSendEmailMessage();
var groupRequiredValidator = (document.getElementById("<%= ReqValGroup.ClientID %>"));
var groupCustomValidator = (document.getElementById("<%= CusValGroup.ClientID %>"));
var txtEmailSubjectRequiredValidator = (document.getElementById("<%= ReqValEmailSubject.ClientID %>"));
/* if ((groupRequiredValidator != null) || (groupCustomValidator != null) || (txtEmailSubjectRequiredValidator != null)) */
/* { */
var forceShow = true;
ShowHideMoreOptions(forceShow);
/* } */
RenderSharingInformation();
SetInitialFocus();
}

...

<!-- <div class="ms-core-form-section">
<asp:PlaceHolder id="PanelShowHideMoreOptions" runat="server">
<wssuc:FoldHyperLink runat="server" LinkTitleWhenFoldClosed="<%$Resources:wss,aclinv_ShowOptions%>" LinkTitleWhenFoldOpened="<%$Resources:wss,aclinv_HideOptions%>" CustomClientClick = "ShowHideMoreOptions();" />
</asp:PlaceHolder>
</div> -->
<!-- More Options section is initially hidden; ShowHideMoreOptions controls the display of this div when link clicked -->
<div class="ms-core-form-section">
<div id="divMoreOptions" style="display:none;">
<asp:PlaceHolder id="PanelSendEmail" runat="server" visible="false">
<div class="ms-core-form-subsection">
<asp:CheckBox runat="server" id="chkSendEmailv15" Checked="false" class = "ms-aclinv-checkbox" OnClick="UpdateSendEmailMessage()"/>
<label for=<%SPHttpUtility.WriteAddQuote(SPHttpUtility.NoEncode(chkSendEmailv15.ClientID),this.Page);%>>
<SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,aclinv_SendEmailCheckboxv15%>" EncodeMethod='HtmlEncode'/>
</label>
<div id="divSendEmailOptions" style="display:none";>
<div class="ms-aclInv-emailOptions-heading"><SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,aclver_SubjectLabelv15%>" EncodeMethod='HtmlEncode'/></div>
<wssawc:InputFormTextBox title="<%$Resources:wss,aclver_SubjectTitle%>" CssClass="ms-fullWidth" ID="txtEmailSubject" Columns="35" Runat="server" MaxLength=512 OnChange="OnSubjectChanged()" />
<wssawc:InputFormRequiredFieldValidator id="ReqValEmailSubject" runat="server" CssClass="ms-error" BreakBefore="false" EnableClientScript ="false" ControlToValidate="txtEmailSubject"/>
</div>
</div>

...

And after we have saved our changes your dialog will look like this:

That´s it. Your work is done.

SharePoint 2016

This is your default dialog on SharePoint 2016:

To change the default dialog open the AclInv.aspx file located here C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\TEMPLATE\LAYOUTS\AclInv.aspx. Now search for chkSendEmailv15 and change Checked=True to Checked=False.
Since I did not like the SHOW OPTIONS/HIDE OPTIONS link because I noticed that it confuses inexperienced users more than it is useful to them I commented out some code to remove it as you can see in the below code snippets.

...
 
function _spBodyOnLoad()
{
txtEmailBodyIsEmpty = InitializeGhostedElement((document.getElementById("<%= txtEmailBody.ClientID %>")), L_EmailBodyGhostedText, formLongInputGhosted, formLongInputNonGhosted, null);
UpdateAddToGroupOrRole();
UpdateWelcomeInheritMessage();
UpdateGivePermissionsHeading();
UpdateSendEmailMessage();
var groupRequiredValidator = (document.getElementById("<%= ReqValGroup.ClientID %>"));
var groupCustomValidator = (document.getElementById("<%= CusValGroup.ClientID %>"));
var txtEmailSubjectRequiredValidator = (document.getElementById("<%= ReqValEmailSubject.ClientID %>"));
if ((groupRequiredValidator != null) || (groupCustomValidator != null) || (txtEmailSubjectRequiredValidator != null))
{
var forceShow = true;
ShowHideMoreOptions(forceShow);
}
RenderSharingInformation();
SetInitialFocus();
}

...

<div class="ms-core-form-section ms-aclinv-show-hide-options">
<asp:PlaceHolder id="PanelShowHideMoreOptions" runat="server">
<wssuc:FoldHyperLink runat="server" LinkTitleWhenFoldClosed="<%$Resources:wss,aclinv_ShowOptions%>" LinkTitleWhenFoldOpened="<%$Resources:wss,aclinv_HideOptions%>" CustomClientClick = "ShowHideMoreOptions();" />
</asp:PlaceHolder>
</div>

...
 
<asp:CheckBox runat="server" id="chkSendEmailv15" Checked="true" class = "ms-aclinv-checkbox" OnClick="UpdateSendEmailMessage()"/>

...
...
 
function _spBodyOnLoad()
{
txtEmailBodyIsEmpty = InitializeGhostedElement((document.getElementById("<%= txtEmailBody.ClientID %>")), L_EmailBodyGhostedText, formLongInputGhosted, formLongInputNonGhosted, null);
UpdateAddToGroupOrRole();
UpdateWelcomeInheritMessage();
UpdateGivePermissionsHeading();
UpdateSendEmailMessage();
var groupRequiredValidator = (document.getElementById("<%= ReqValGroup.ClientID %>"));
var groupCustomValidator = (document.getElementById("<%= CusValGroup.ClientID %>"));
var txtEmailSubjectRequiredValidator = (document.getElementById("<%= ReqValEmailSubject.ClientID %>"));
/* if ((groupRequiredValidator != null) || (groupCustomValidator != null) || (txtEmailSubjectRequiredValidator != null)) */
/* { */
var forceShow = true;
ShowHideMoreOptions(forceShow);
/* } */
RenderSharingInformation();
SetInitialFocus();
}
 
...
 
<!-- <div class="ms-core-form-section ms-aclinv-show-hide-options">
<asp:PlaceHolder id="PanelShowHideMoreOptions" runat="server">
<wssuc:FoldHyperLink runat="server" LinkTitleWhenFoldClosed="<%$Resources:wss,aclinv_ShowOptions%>" LinkTitleWhenFoldOpened="<%$Resources:wss,aclinv_HideOptions%>" CustomClientClick = "ShowHideMoreOptions();" />
</asp:PlaceHolder>
</div> -->

...
 
<asp:CheckBox runat="server" id="chkSendEmailv15" Checked="false" class = "ms-aclinv-checkbox" OnClick="UpdateSendEmailMessage()"/>

...

And after we have saved our changes your dialog will look like this:

That´s it. Your work is done.

I hope you liked my post and I hope to see you again next time 🙂

Sources:

http://jurisinnenad.blogspot.co.at/2016/09/disable-default-send-email-invitation.html

http://sharepointcherie.blogspot.co.at/2013/09/sharepoint-2013-disable-default-on-e.html

Advertisements
Tagged

SharePoint – Customize Wiki Headings with CSS

Hello everyone. Today I want to show you how you can customize the Wiki Headings of a SharePoint 2010 Wiki via CSS to make them look better.

Here you can see all Headings and Colored Headings in their default style. (Not really pretty in my opinion)

sharepoint_wiki_headings_before

To change this we will do the following:

First you need to enable the SharePoint Site Collection and SharePoint Site Feature called “SharePoint Server Publishing Infrastructure”.

Next we create our custom CSS File. I called mine “Wiki.css”. Here is the code:


.s4-recentchanges
{
display:none;
}

.ms-rteElement-H1
{
font-size:xx-large !important;
font-weight:normal;
font-style:normal;
}

.ms-rteElement-H2
{
font-size:x-large !important;
font-weight:normal;
font-style:normal;
}

.ms-rteElement-H3
{
font-size:large !important;
font-weight:normal;
font-style:normal;
}

.ms-rteElement-H4
{
font-size:medium !important;
font-weight:normal;
font-style:normal;
}

.ms-rteElement-H1B
{
color:#ff8c00;
font-size:xx-large !important;
font-weight:normal;
}

.ms-rteElement-H2B
{
color:#ff8c00;
font-size:x-large !important;
font-weight:normal;
}

.ms-rteElement-H3B
{
color:#ff8c00;
font-size:large !important;
font-weight:normal;
}

.ms-rteElement-H4B
{
color:#ff8c00;
font-size:medium !important;
font-weight:normal;
font-style:normal;
}

After you have finished creating your CSS file upload it somewhere to your SharePoint Site Collection.

Next go to Site Actions > Site Settings >  Look and Feel > Master page and select the CSS File “Wiki.css” we created and uploaded to SharePoint and click on OK.

sharepoint_css_navigation_setting

After you have finished the above steps your Wiki Headings will look like this:

sharepoint_wiki_headings_after

Much better than the default Headings right? Well that´s it. Now you know how to customize your Wiki Headings to create better Wiki pages. I hope you liked my post and I hope to see you again 🙂

Sources:

http://junestime.wordpress.com/2012/05/22/change-the-default-markup-style-3/

http://www.ironspider.ca/adv/cssproperties/fontstyles.htm

http://www.w3schools.com/cssref/pr_font_font-size.asp

Tagged ,

SharePoint – Toplink Fly Out Menus

Hello everyone,

today I want to show you something I found out about SharePoint when I played around with some features. I want to show you how you can enable Fly Out menus in your Toplink Bar without using SharePoint Designer.

Important: You need SharePoint Server. As far as I know this solution does not work on SharePoint Foundation.

The first thing you need to do is to go to your SharePoint Site and enable the Site Collection Feature and Site FeatureSharePoint Server Publishing Infrastructure“.

sharepoint_toplink_features

Now click on the Navigation link.

sharepoint_toplink_site_settings

Now create a new Heading under Global Navigation and add some links:

sharepoint_toplink_navigation

Now go back to your Site and have a look at the Toplink Bar. It should look like this:

sharepoint_toplink_links

That´s it. Pretty simple right? I hope you liked my post and I hope to see you next time 🙂

Sources:

I tried this when I had some free time 🙂

Tagged

SharePoint – How to use mathematical formulas on your pages

Hello everyone. Today one of my clients asked me if it is possible to add mathematical formulas to SharePoint pages. I found a solution here that gives you the possibility to generate gif images from Latex code. Please give the guys from codecogs some credit for their awesome solution and donate some money if you liked this solution.

Now lets get down to business 🙂

Here is the example code I used to add the Theorem of Pythagoras to my SharePoint page:

<html>
<head>
<script type="text/javascript" src="http://latex.codecogs.com/latexit.js"></script>
</head>
<body>
<h1>Theorem of Pythagoras</h1>
<div lang="latex">a^2 + b^2 = c^2</div>
</body>
</html>

Upload the above script to your SharePoint site and add a Content Editor Web Part to the page. Add the link to your script to the Content Editor Web Part.

sharepoint_math_formula_editor

The result will look like this:

sharepoint_math_formula_finished

Pretty simple right? This way you can add all kinds of mathematical formulas to your SharePoint pages.

I hope you liked my post and I hope to see you again next time 🙂

Sources:

http://www.codecogs.com/latex/integration/htmlequations.php

http://stackoverflow.com/questions/11824093/how-to-integrate-a-shortcode-feature-in-sharepoint-wikis

Tagged ,

SharePoint – Use JQuery to highlight rows

Hello everyone. Today I want to show you how you can use jQuery and SPServices to conditionally highlight rows of your SharePoint Web Parts.

Here is the script you need:

<script type="text/javascript" src="/sites/test2/Script/jquery.min.js"></script>
<script type="text/javascript" src="/sites/test2/Script/jquery.SPServices.min.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready(function() {
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Test",
CAMLQuery: "<Query><Where><Eq><FieldRef Name='YesNoField' /><Value Type='Integer'>1</Value></Eq></Where></Query>",
CAMLViewFields: "<ViewFields> <FieldRef Name='ID' /> </ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {

$("tr[iid*='"+ $(this).attr("ows_ID").toString() + "']").css("background-color", "#A3F02E");

});
}
});
});

</script>

The above Script will check the value of the “YesNoField” column in your “Test” List and if the value is “Yes” (1) it will highlight the row. If the value is “No” (0) it will do nothing.

To use the script click on Edit Page on your website and add your List Web Part and a Content Editor Web Part and add a link to your script to the Content Editor Web Part. (You need to store the script somewhere on your website in a Library.)

sharepoint_setup_highlighted_row

If you set up everything correctly the result will look like this:

sharepoint_highlighted_row

That´s it. You can now use this method to highlight specific rows. I hope you liked my post. See you next time 🙂

And as always you can download my script from here.

Sources:

http://mekalikot.blogspot.co.at/2014/01/highlight-sharepoint-task-list-row.html

http://spservices.codeplex.com/wikipage?title=GetListItems

http://social.msdn.microsoft.com/Forums/sharepoint/en-US/1905cd40-c66b-4865-a036-299c88b8bc51/how-to-write-caml-query-for-yes-no-field

http://mekalikot.blogspot.co.at/2014/07/highlight-row-change-font-color-and.html

Tagged ,

SharePoint – Use JQuery to hide columns based on a Users Group Membership

Hello everyone. Today I want to show you how you can use jQuery and SPServices to hide SharePoint columns based on a users group membership.

In a previous post I explained how you can use jQuery and SPServices to Auto-Fill fields. Please follow the instructions in this post but use the script below instead in your NewForm.aspx and/or EditForm.aspx pages.


<script type="text/javascript" src="/sites/test/Script/jquery.min.js"></script>
<script type="text/javascript" src="/sites/test/Script/jquery.SPServices.min.js"></script>

<script language="javascript" type="text/javascript">
$(document).ready(function()
{
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function (xData, Status) {
var xml = xData.responseXML.xml;
if(xml.search('SharePoint Group') != -1)
{

$('nobr:contains("TestColumn")').closest('tr').hide();

}
}
});
});
</script>

Replace “TestColumn” with the Name of your column you want to hide. And replace “SharePoint Group” with the Name of your SharePoint Group. If you configured everything correctly your column will be hidden for members of the SharePoint Group you defined in the script. (To hide a column for everyone except a specific group replace

if(xml.search('SharePoint Group') != -1)

with

if(xml.search('SharePoint Group') == -1)

)

That´s it. Now you are able to hide columns from specific user groups. I hope you liked my post. See you next time 🙂

And as always you can download my script from here.

Sources:

http://www.sharepointnadeem.com/2011/09/hide-sharepoint-list-field-based-on.html

http://sharepointroot.com/2011/09/23/sharepoint-2010-how-to-hide-blog-fields-using-jquery/

https://theezitguy.wordpress.com/2014/05/26/sharepoint-auto-fill-fields-using-jquery-and-spservices/

Tagged ,

SharePoint – Use Event Receiver to Auto-Increment columns

Hello everyone. Today a customer wanted a solution to automatically increment column values. Since he wanted to be able to configure the solution in a simple manner I decided to create an Event Receiver solution.

To create the solution log into your development machine and open Visual Studio. Choose Event Receiver as Project Template and deploy it as a Sandboxed solution.

Here is the code:

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace AutoIncrement.EventReceiver1
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item was added.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);

using(SPWeb web = properties.Web)
{
int startValue = 0;
int incrementValue = 1;
String columnName = "";
int highestValue = 0;

//Query "AutoIncrementLists" for information
SPList list = web.Lists["AutoIncrementLists"];
SPQuery query = new SPQuery();
query.Query = String.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + properties.ListTitle + "</Value></Eq></Where>");
SPListItemCollection items = list.GetItems(query);

if (items.Count > 0)
{
//iterate through each Query Result
foreach (SPListItem item in items)
{
startValue = int.Parse(item["StartValue"].ToString());
incrementValue = int.Parse(item["IncrementValue"].ToString());
columnName = item["ColumnName"].ToString();

//Query current List for highest value
SPList incrementList = web.Lists[properties.ListTitle];
SPQuery incrementQuery = new SPQuery();
incrementQuery.Query = String.Format("<OrderBy><FieldRef Name='" + columnName + "' Ascending='False' /></OrderBy><RowLimit>1</RowLimit>");
SPListItemCollection incrementItems = incrementList.GetItems(incrementQuery);

//Check if query return items
if (incrementItems.Count > 0)
{
//Check if there are items with a value for the column columnName
if (incrementItems[0][columnName] != null)
{
highestValue = int.Parse(incrementItems[0][columnName].ToString());
}
}

SPListItem currentItem = properties.ListItem;

//Increment column
if (highestValue >= startValue)
{
currentItem[columnName] = highestValue + incrementValue;
currentItem.Update();
}
else
{
currentItem[columnName] = startValue + incrementValue;
currentItem.Update();
}
}
}
}
}
}
}

The code does the following:

It iterates through a Custom List called “AutoIncrementLists” and gets information from the columns Title, ColumnName, StartValue and IncrementValue. This information is used to update the current List Item which was added recently. (The solution I created only applies to Custom Lists.)

After you have created the solution you need to upload the solution to your Test site and activate it.

sharepoint_autoincrement_solutions

Now activate your Site feature. Mine is called “AutoIncrement for Custom Lists”.

sharepoint_autoincrement_site_feature

Next you need to create a Custom List called AutoIncrementLists and add the following columns:

  • Title (Single line of text): The Custom Lists Title
  • ColumnName (Single line of text): The Column Name
  • StartValue (Single line of text): The “Begin” of your Counter
  • IncrementValue (Single line of text): The value added to your Counter for each new item

You need this list on every site you want to use this feature.

sharepoint_autoincrement_settings_list

Here is an example of my “AutoIncrementLists” list:

sharepoint_autoincrement_settings_list_example

Here is the example of the “AutoInc1” list:

sharepoint_autoincrement_example1

And here is the example of the “AutoInc2” list:

sharepoint_autoincrement_example2

That´s it. Now you have a solution which allows you to automatically increment your columns every time an item is added. I hope you liked my post. See you next time.

As always you can download my code from here.

Sources:

http://social.technet.microsoft.com/forums/sharepoint/en-US/39743bb3-872d-4788-96a8-2b9fb8813011/create-auto-increment-value-in-sharepoint-column

http://faisalrafique.wordpress.com/2011/03/19/creating-auto-increment-field-in-sharepoint-list/

http://stackoverflow.com/questions/15929903/sharepoint-list-item-throws-null-error

http://stackoverflow.com/questions/3903986/programmatically-setting-field-value-for-sharepoint-listitem

https://theezitguy.wordpress.com/2014/08/22/sharepoint-event-receiver-to-prevent-documents-from-being-deleted/

Tagged ,

SharePoint – Use JQuery to set Column Width

Hello everyone. Today I was asked to alter the column width of some SharePoint Web Parts to improve the look and feel of a site. I altered the column width with a simple Javascript and JQuery.

Here is an example how the Web Parts of the site looked before I added my script:

sharepoint_before_column_width_script

Not pretty but luckily there is a simple way to change that.

Here is the script code:

<script src="/sites/test/Scripts/jquery.min.js"></script>
<script language="javascript">
$(function(){
$("TH.ms-vh2:contains('Name')").css("width", "300px");
});
</script>

With the above script you can alter the width of any column you want. You simply need to replace “Name” in the script with the Display Name of your Column.

To use the script you need to add a Content Editor Web Part to your site and embed your script in it.

sharepoint_add_column_width_script

After you have applied your script to the site your site will look like this:

sharepoint_after_column_width_script

Looks better than before, right? Well, that´s it. That´s all you need to do. I hope you liked my post. See you next time.

Sources:

http://social.technet.microsoft.com/Forums/sharepoint/en-US/eab8a3ca-1a91-45ca-b7d5-a5f78592083e/adjust-column-width-in-sharepoint-2013?forum=sharepointgeneral

http://www.emmielewis.com/changesplistcolumnwidth/

Tagged ,

SharePoint – Event Receiver to prevent documents from being deleted

Hello everyone. A few days ago I got a request to find a solution for the following problem: My customer has some Document Libraries where he stores important documents. These documents mustn´t be deleted since those documents are important contracts. So what can you do to prevent this?

Well there are some ways to achieve this: You can create a new Permission Level which does not allow the Delete action or you can create an Event Receiver which cancels the Delete action and throws an error message. I chose the second option since my customer and I both wanted to provide the user some information why his Delete action was canceled. (The first option would simply grey out the Delete action possibly resulting in users thinking there is something wrong with the software system.)

To create the Event Receiver do the following:

First open up Visual Studio on your Development machine and choose New Project. Select Event Receiver as your project template.

sharepoint_deleting_event_receiver

Next I chose Deploy as a sandboxed solution. (A sandboxed solution is enough for our planned actions.)

sharepoint_deleting_event_receiver_sandbox

Next select Document Library from the Dropdown and check An item is being deleted as event.

sharepoint_deleting_event_receiver_settings

And here is the code:

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace SPDeletedReceiver.EventReceiver1
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item is being deleted.
/// </summary>
public override void ItemDeleting(SPItemEventProperties properties)
{
base.ItemDeleting(properties);

using(SPWeb web = properties.Web)
{
SPList list = web.Lists["DoNotAllowDelete"];
SPQuery query = new SPQuery();
query.Query = string.Format("<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + properties.ListTitle + "</Value></Eq></Where>");
SPListItemCollection items = list.GetItems(query);

if(items.Count > 0)
{
properties.ErrorMessage = "You are not allowed to delete items.";
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.Cancel = true;
}
}
}
}
}

Code Explanation: The actions of the code are not very complex. What it simply does is check if the List Title of the List where the Delete action was triggered is listed in a Custom List called “DoNotAllowDelete”. If the List Title is listed the Delete action will be canceled. If not the Delete action will be executed.

So you are basically black listing some Document Libraries where the Delete action is forbidden for everyone.

To use the Event Receiver you need to upload the solution wsp file to your Solutions in your Site Collection and activate it. And you must activate the Event Receivers feature on the sites (Site features) where you want to use the solution.

Important: You also need to create a Custom List called “DoNotAllowDelete” on each Site you want to use the solution. And you need to enter the Library Titles of your black listed Document Libraries into the Title column of this list.

Here is an example picture of my “DoNotAllowDelete” list:

sharepoint_event_receiver_donotallowdelete

As you can see I black listed the Document Library “Documents”. If I now try to delete a document is the “Documents” library I will receive an error message like you can see below and the the document will not be deleted.

sharepoint_deleting_event_receiver_error_message

Well that´s it. I hope my post was interesting for you. See you next time.

As always you can download my code from here.

Sources:

http://planetlotus.org/profiles/bram-nuyts_116783_prevent-items-from-being-deleted-using-an-event-receiver

Tagged ,

Nintex Workflow – Custom Inline Function

Hi everyone. Today I want to show you how you can develop custom inline functions for the Nintex Workflow product for SharePoint.

I got the idea from here (Absolutely great post.) but I created a SharePoint solution file because I thought this would be a bit simpler to use.

First open Microsoft Visual Studio and create a new Empty SharePoint Project. Remember to deploy it as a farm solution.

nintex_custom_inline_new_sharepoint_project

Now add a new Class. I called mine “Function.cs”.

nintex_custom_inline_code

Here is some example code I added to my class. (I got the code also from here.)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CustomNintexInline
{
class Function
{
public static int Random()
{
Random rnd = new Random(Environment.TickCount);
return rnd.Next();
}

public static int Random(int _iMax)
{
Random rnd = new Random(Environment.TickCount);
return rnd.Next(_iMax);
}

public static int Random(int _iMin, int _iMax)
{
Random rnd = new Random(Environment.TickCount);
return rnd.Next(_iMin, _iMax);
}
}
}

Now build your project.

After you successfully built your project run cmd as Administrator and go to the following path:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin

Next run the following code to retrieve the Public key token:

sn.exe -T "Path-To-Your-dll/Project.dll"

Write down the value of your Public key token you will need it later.

nintex_cutom_inline_sn

Next you need to add your solution file to your SharePoint Farm. Do this by running PowerShell as Administrator and by running the following commands:

Add-PSSnapin Microsoft.SharePoint.PowerShell
Add-SPSolution "Full-Path-To-Your-WSP/Project.wsp"

nintex_custom_inline_add_solution

Next open your SharePoint Central Administration and deploy your solution globally.

nintex_custom_inline_solution

Next go to:

C:\Program Files\Nintex\Nintex Workflow 2010

Now run cmd as Administrator and run the following code to add your custom inline function to your Nintex Workflow product:

NWAdmin.exe -o addinlinefunction -functionalias "fn-Random (The string alias used to use your function later in your workflows)" -assembly "CustomNintexInline, Version=1.0.0.0,  Culture=neutral, PublicKeyToken=<Value you retrieved before by using sn.exe> (dll data)" -namespace "CustomNintexInline (Namespace of your Project)" -typename "Function (Class of your Project containing your function)" -method "Random (Method/Function name in your Project)" -description "<A short description what your function does>" -usage "<How to use your function>"

If the above command finishes without error messages your custom inline function has been successfully added to your Nintex Workflow product.

nintex_custom_inline_nwadmin

Next run cmd as Administrator and run the following command to restart IIS:

iisreset

That´s it. Now your custom inline function should be available. To test it I created a simple Nintex Workflow:

nintex_custom_inline_test_workflow

When you go to Inline Functions in one of your Nintex Workflow Actions you will find your custom inline function. (Called “Random” in my example)

nintex_custom_inline_use

Here you can see the result of my Test workflow:

nintex_custom_inline_test_mail

As you can see everything worked as expected and your custom inline function is ready to use. I hope you liked my today´s post. See you next time.

As always you can download my code from here.

Sources:

http://www.vadimtabakman.com/nintex-workflow-developing-a-custom-inline-function.aspx

Tagged ,