Tag Archives: sharepoint

SharePoint: Configure App Domain on Host Header Environments

So I have configured a host header web application and the application domain (apps.domain.com). I was able to download and install apps from the apps store, but when I click on the app the I get an error 404 Not Found.

While doing some digging around on the Internet I discovered there is a PowerShell cmdlet that I can run to configure app domain and web application. If have already created a app domain in your DNS, you will need to create a new host header web application using the app domain name (http://apps.domain.com).

To configure your app domain use the following cmdlet:

New-SPWebApplicationAppDomain -AppDomain <AppDomain> -WebApplication <WebApplicationID> -Zone <Zone> -Port <Port> -SecureSocketsLayer

Where:

  • <AppDomain> is the URI of the app domain. This parameter is required.
  • <WebApplicationID> is the GUID, URI, or name of the web application for which the app domain is being configured. This parameter is required.
  • <Zone> is the security zone to which the app domain will be assigned. Possible values are “Default”, “Intranet”, “Internet”, “Custom”, or “Extranet”. If no value is specified “Default” will be applied. This parameter is optional.
  • <Port> is the IIS port number to which the app domain will be assigned. If no value is specified, the same port that is used by the web application for the zone will be applied. This parameter is optional.
  • -SecureSocketsLayer is a parameter to specify that the app domain will use Secured Sockets Layer (SSL) security. If no value is specified, no SSL security will be used.This parameter is optional.

To remove the app domain use the following cmdlet:

Remove-SPWebApplicationAppDomain -WebApplication <WebApplicationID> -Zone <Zone>

Where:

  • <WebApplicationID> is the GUID, URI, or name of the web application for which the app domains will be removed. This parameter is required.
  • <Zone> is the security zone from which the app domain will be removed. Possible values are “Default”, “Intranet”, “Internet”, “Custom”, or “Extranet”. If no value is specified, all of the app domains for the web application will be removed. This parameter is optional.

 

SharePoint: Web Application Creation Fails

If you have noticed after you have created a few web applications in SharePoint Central Administration, your new web application doesn’t complete it’s process normally and at the end you see an error message in a dialog saying it can’t find the following URL address.

But if you think that your site has been created successfully, well don’t keep your hopes up because it didn’t. The reason for this is because the more web application is created the time in which it takes to create a web application increases.  As part of the creation process, IIS is reset and by default, the application pool allows 90 seconds for the connections to close off before shutting down. When the number of web application grows above 90 seconds its not enough time for the provisioning to complete.

Don’t worry, I have done some searching around and found a resolution, by increasing the time longer before it shutdowns:

  1. On the same server that is hosting Central Administration, open IIS Manager.
  2. Expand the Application Pools section.
  3. Find the SharePoint Central Administration  application pool. Right click and choose Advance Settings.
  4. In the Process Model section set the Shutdown Time Limit to a higher value. Eg. 300
  5. Restart IIS.

 

SharePoint: How To Create a SharePoint Permission Group and Add Users Programmatically

Using C# and SharePoint Object Model I will show you how to add a user to an existing or newly created SharePoint Permission Group.

I was working on a project that requires a domain user to be added to the site’s visitors group automatically base on events, and my project is developed in Microsoft Visual Studio so I need write some code to achieve this.

Below is an example code snippet that will show you how to to use SiteGroups.Add() to create a new SharePoint Group and assign the Read permission level by using RoleDefinitionBindings.Add(), add a default user and a group owner:

using (var spSite = new SPSite("SiteURL"))
{
	using (var web = spSite.OpenWeb())
	{
		var groupName = "Group Name";
		var groupDescription = "Group Description";
		var groupOwner = "contoso\jbloggs";
		var defaultUser = "contoso\jdoe";
		
		
		web.SiteGroups.Add(groupName, groupOwner, defaultUser, groupDescription);
		
		var group = web.SiteGroups[groupName];
		var spRoleAssignment = new SPRoleAssignment(group);
		var permissionName = "Read";
		
		spRoleAssignment.RoleDefinitionBindings.Add(web.RoleDefinitions[permissionName]);
		web.RoleAssignments.Add(spRoleAssignment);

		web.Update();
	}
}

Continue reading

Surface Pro 3 for General and SharePoint Development

I bought my Surface Pro 3 in April 2015 as my dedicated development computer for .NET and SharePoint development. The Surface Pro 3 has 8GB of RAM, 512GB of storage and i7 CPU. Compared to my previous desktop setup, I had 16GB of RAM, 2TB of HDD Storage, and AMD Quad Core CPU.

Surface-Pro-3 Continue reading

SharePoint 2013 Promoted Links Target=”=” Issue

Recently I had a colleague looking into an issue with Promoted Links not opening into a new tab in SharePoint 2013. So I thought I will look into it and see how it could be fixed using a bit of JavaScript.

To test this problem I have created a Promoted Link called My Links and added two items. Create an new item for a link to google.com and bing,com web site:

sharepoint_promoted_link_issue_01

When you click on either one of the tiles it will open a new tab, don’t close the tab and return to the tab where the Promoted Links were. Now click on the other tile and you can see that it open in the same tab as the previous tile. Continue reading

SharePoint 2013: Retrieving User’s Profile using Client Side Object Model

SharePoint-logo-1024x325

Using the SharePoint Client Side Object Model you can retrieve a specific user’s profile from SharePoint. I have put together a simple console application in Visual Studio and I have described each line of code below.

On the 1st line of code instantiate the ClientContext class by passing your site’s URL.

On the 2nd line I instantiate PeopleManager class which provides methods for operations on people in SharePoint.

On 3rd line I instantiate the UserProfilePropertiesForUser class by passing the client context, the user’s name and an array of strings containing the property names.

On the 4th line I use the GetUserProfilePropertiesFor method from the PeopleManager and passing it the UserProfilePropertiesForUser object I have created earlier on. This method will return a list of string values that we can use a foreach loop to iterate through the values.

var clientContext = new ClientContext("http://yoursite/");

var peopleManager = new PeopleManager(clientContext);

var userProfile = new UserProfilePropertiesForUser(clientContext, "domain\username", new[] {"FirstName", "AboutMe", "Manager"});

var profileProperties = peopleManager.GetUserProfilePropertiesFor(userProfile);

clientContext.ExecuteQuery();

foreach (var str in profileProperties)
{
	Console.WriteLine(str);
}

Console.ReadKey();

SharePoint 2013: WebParts and Basic AngularJS

 

SharePoint2013_AngularJS_Logo

In this post I am going to show you how to apply AngularJS to your Visual WebParts in SharePoint.

Create a SharePoint 2013 Solution.

From Visual Studio menu File->New->Project and then use the SharePoint 2013 – Empty Project Template. Name the project DemoSite1 and the solution SharePoint2013 and click OK to continue. While Visual Studio is preparing your solution why not go and make yourself some coffee!

SP2013_WebParts_AngularJS_00

Right click on the DemoSite1 project and from the popup menu select Add->SharePoint “Layouts” Mapped Folder. After you have created the Layouts folder you will see another sub folder  called DemoSite1. So in the Layouts folder create a Scripts folder, and then create another Scripts folder inside the DemoSite1 folder.

Continue reading

SharePoint 2013: How To Create A New Site Collection

To create a new site collection on SharePoint 2013 server, open Central Administration and under the Application Management section select Create site collections:

SP2013 Create Site Collection 1

Enter a Title and Description for your site, so for the title I am using Demo Site 1. Web Site Address you may select an alternative URL Path or use the default URL Path sites and then enter your URL name, for this demonstration I will use DemoSite1.

SP2013 Create Site Collection 2

Continue reading

SharePoint: How to Change The Default Welcome Page on a Site

If you want to programmatically set a site’s default welcome page you can write the following code to redirect it to another page within the site.

The url path must relative and you MUST create another SPFolder object to reference the RootFolder and perform your update, or else it won’t work:

using Microsoft.SharePoint;

namespace SharePointConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var spSite = new SPSite("http://spdev/test"))
            {
                using (var spWeb = spSite.OpenWeb())
                {
                    var rootFolder = spWeb.RootFolder;
                    rootFolder.WelcomePage = "Lists/Events/AllItems.aspx";
                    rootFolder.Update();
                }
            }
        }
    }
}

SharePoint 2010: Event Receiver ItemAdding and ItemUpdating How To Set AfterProperties DateTime Field Value

If you are receiving this error “Invalid date/time value. A date/time field contains invalid data. Please check the value and try again.”. This is because the assigning value for the AfterProperties DateTime field in the ItemAdding or ItemUpdating event in the Event Receiver was not formatted correctly.

To resolve this issue you need to format the DateTime value to an ISO8601 string format:

properties.AfterProperties["StartDate"] = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");

or by using the SPUtility.CreateISO8601DateTimeFromSystemDateTime method:

properties.AfterProperties["StartDate"] = Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now);