CHUVASH.eu
  • About
  • Search

Posts

November 22, 2012

Create SPGroup in PowerShell

Thanks to Ryan for sharing powershell functions. I used New-SPGroup which I altered. Now You can define which permissions will be given to the new group. You can even create groups without default users. Here it comes:

 
function New-SPGroup {
<#
.Synopsis
	Use New-SPGroup to create a SharePoint Group.
.Description
	This function uses the Add() method of a SharePoint RoleAssignments property in an SPWeb to create a SharePoint Group.
.Example
New-SPGroup -Web http://intranet -GroupName "Test Group" -OwnerName DOMAIN\\User -MemberName DOMAIN\\User2 -Description "My Group" -Role "Read"
	This example creates a group called "Test Group" in the http://intranet site, with a description of "My Group".  The owner is DOMAIN\\User and the first member of the group is DOMAIN\\User2 and adds "Limited Access".
	C:\\PS>New-SPGroup -Web http://intranet -GroupName "Test Group" -OwnerName DOMAIN\\User -MemberName DOMAIN\\User2 -Description "My Group" -Role "Read"
	This example creates a group called "Test Group" in the http://intranet site, with a description of "My Group".  The owner is DOMAIN\\User and the first member of the group is DOMAIN\\User2 and adds "Read" access.
	Pay attention to the role definition names. They must be provided in the language of your site.
.Notes
	Name: New-SPGroup
	Author: Ryan Dennis, Anatoly Mironov
	Last Edit: 2012-11-05
	Keywords: New-SPGroup, spgroup, permissions
.Link
	http://www.sharepointryan.com
 	http://twitter.com/SharePointRyan
	https://sharepointkunskap.wordpress.com
.Inputs
	None
.Outputs
	None
#Requires -Version 2.0
#>
	\[CmdletBinding()\]
	Param(
	\[Microsoft.SharePoint.PowerShell.SPWebPipeBind\]$Web,
	\[string\]$GroupName,
	\[string\]$OwnerName,
	\[string\]$MemberName,
	\[string\]$Role,
	\[string\]$Description
	)
	$SPWeb = $Web.Read()
	if ($SPWeb.SiteGroups\[$GroupName\] -ne $null){
		throw "Group $GroupName already exists!"	
	}

	if ($Role) {
		$roleDefinition = $SPWeb.RoleDefinitions\[$Role\]
		if (!$roleDefinition) {
			throw "Role Definition $Role doesn't exist!"
		}
	}

	if ($SPWeb.Site.WebApplication.UseClaimsAuthentication){
		$op = New-SPClaimsPrincipal $OwnerName -IdentityType WindowsSamAccountName
		$owner = $SPWeb | Get-SPUser $op
		if ($MemberName) {
			$mp = New-SPClaimsPrincipal $MemberName -IdentityType WindowsSamAccountName
			$member = $SPWeb | Get-SPUser $mp
		}
	}
	else {
	$owner = $SPWeb | Get-SPUser $OwnerName
		if ($MemberName) {
			$member = $SPWeb | Get-SPUser $MemberName
		}
	}

	$SPWeb.SiteGroups.Add($GroupName, $owner, $member, $Description)
	$SPGroup = $SPWeb.SiteGroups\[$GroupName\]	
	$roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($SPGroup)
	if ($Role) {
		$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)
	}
	$SPWeb.RoleAssignments.Add($roleAssignment)
	$SPWeb.Dispose()
	return $SPGroup
}
read more
November 22, 2012

AngularJS: sync $location.search with an input value

I have used AngularJS for a while and to me this seems to be the best MVC javascript framework. Today I wanted to implement a search which uses an input and a hash query string like in google. The input value and url have to be synced like:

index.html#?term=something

To do this we have to inject $location into our angular control. See the Angular Guide about $location. Then we have to observe both the $scope.term (which is bound to the input value) and $location.search().

read more
November 8, 2012

Determine if Silverlight is installed (javascript)

For a while ago I needed to provide an alternative solution when Silverlight isn’t installed. I searched  for javascript code for this and found this:

  • A blog post about that: Piotr Puszkiewicz’s Silverlight Blog. Determining if Silverlight is installed using Javascript.
  • A more advanced javascript function which can even determine the version of the Silerlight can be pulled from Silverlight.js library.

I didn’t need to determine the version of Silverlight, so I wrote a simplified js function (but it works in all browsers): [sourcecode language=“javascript”] var isSilverlightInstalled = function() { var installed = false; try { installed = !!navigator.plugins[“Silverlight Plug-In”] || !!(window.ActiveXObject && new ActiveXObject(‘AgControl.AgControl’)); } catch (e) {} return installed; };[/sourcecode] This function first checks if a Silverlight plugin is installed in almost all web browsers except IE, then if it is not it tries to create an ActiveXObject (IE) for Silverlight. If an error occurs, the function returns false and indicates that Silverlight is not available.

read more
October 30, 2012

JSOM: Alter a column's DisplayName

Here is another article in my JSOM series. For one month ago I showed how to alter a column’s ShowInDisplayForm property with JSOM. This time I’ll show a code sample for changing a column’s (field’s) display name. If you want to alter the displayname with Server Object Model, grab the code in the sharepoint.stackexchange.com: Change Field’s DisplayName in a List. [sourcecode language=“javascript”]var ctx = SP.ClientContext.get_current(), //SP.ClientContext field = ctx.get_web() //SP.Web .get_lists() //SP.ListCollection .getByTitle(‘MyList’) //SP.List .get_fields() //SP.FieldCollection .getByInternalNameOrTitle(“Body”); //SP.Field ctx.load(field, “Title”); //load only Title ctx.executeQueryAsync(function() { field.set_title(“Beskrivning”); field.update(); ctx.executeQueryAsync(); });[/sourcecode]

read more
October 23, 2012

Delete all list items with jsom

Today I needed to “clean” a list, meaning to remove all list items. For some time ago I wrote a post about different ways of removing list items in bulk: Server Object Model, SPLinq and RPC.  This time I had only the web browser. So I tried the jsom way. By the way, the javascript documentation for jsom on msdn is getting really good. Don’t miss that: How to: Complete basic operations using JavaScript library code in SharePoint 2013. Now here comes theworking code I used to remove all items in my list:

read more
October 16, 2012

TypeScript in SharePoint

By now TypeScript shouldn’t be something one has to introduce.

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.

If you haven’t already done it, go and see the intro video for TypeScript, check out a tutorial and visit the typescript playground. There are other javascript libraries which extend javascript and are compatible/compile to javascript: Dart and CoffeeScript. To be honest I had never time to try those. The fact that TypeScript is well integrated into Visual Studio which I happen to work within all the days (intellisense, compilation checks and more) did me curious. This post is actually not about TypeScript itself, but a test to use it in SharePoint. In this short “lab” I even had Web Essentials 2012 which automatically compile typescript files into plain javascript files on save. This is what I did: Install TypeScript and Web Essentials 2012 Create a SharePoint-hosted app: Create a new TypeScript file in the autogenerated “Scripts”-module and call it “Greeter.ts” Just save the file as it is. The new file is created: Greeter.js Now we don’t need to copy this file to the app, so remove Greeter.ts from the Elements.xml file (or comment it out): Open the Default.aspx from the Pages module and add the reference to the new javascript file:

read more
October 12, 2012

GeoLocation Field in SharePoint 2013

In SharePoint 2013 Preview there is a new type of field: GeoLocation which is, like the old SPUrlField, a pair of values. The geolocation is described as longitude and latitude. Unfortunately you can’t add this field in list settings. You have to create this in code. In the provided link you can find the code C# code which uses the Client Object Model. In another link  you can find an example how to create the geolocation file using Server Object Model (in FeatureActivated EventReceiver). If you know me, you might already know that I will propose a JavaScript solution. Here is the code to create a geolocation field in an existing list using JSOM:

read more
October 11, 2012

Callouts in SharePoint 2013 Preview

While ModalDialog is not default for editing list items in SharePoint 2013 Preview, there is a new “popup” element in SharePoint - callout or popover. I would like to recommend these two blogs when you want discover more: Andrey Markeev: Callouts (popovers) в SharePoint 2013 Preview (in Russian) Alex Boev: a three part series: 1. Custom Callouts in the SharePoint 2013 Metro UI: Part 1: Basics 2. Custom Callouts in the SharePoint 2013 Metro UI, Part 2: Actions 3. Custom Callouts in the SharePoint 2013 Metro UI, Part 3: CalloutManager To get introduced with callouts in SharePoint 2013, you can run this code (from Andrey Markeev’s blog):

read more
October 8, 2012

.tfignore - ".gitignore" for TFS

I haven’t used TFS so much. But I like it so far. It works smoothly, both TFS 2012 (on premises) and TFS Preview (online). I really appreciate that Microsoft has been inspired from git - the world’s best VCS :). For example .tfignore which works exactly like the .gitignore file. It is nice that the non-classic Microsoft dot notation convention for naming the hidden files is chosen.  So if you have any files to ignore just do it like you did in your git projects. Here is a .tfignore which I use in my SharePoint project for now. I suppose it will be extended soon:

read more
October 6, 2012

Masked Inputs

Just a quick tip today. If you are looking after masked inputs like the old ASP.NET Ajax Control Toolkit MaskedEdit, you can try jQuery plugin called Masked Input from DigitalBush or even better jquery.inputmask.

read more
  • ««
  • «
  • 18
  • 19
  • 20
  • 21
  • 22
  • »
  • »»
© CHUVASH.eu 2025