Archive for July, 2014

The following procedure shows how to create a sub-site in SharePoint 2013.

Step 1

Log into your SharePoint 2013 site.

Step 2

Click on the “Settings” icon and choose “Site Contents” from the drop-down menu.

 sub-site in SharePoint 2013

Step 3

At the bottom of the page, click on “new subsite” under the “Subsites” header.

 sub-site in SharePoint 2013

Step 4

Enter the “Title” and “Description” of your new subsite, choose the URL for it and select a template for this subsite.

 sub-site in SharePoint 2013

Step 5

Select the necessary permission and navigation settings and click “Create.”

 sub-site in SharePoint 2013

Step 6

Now you can see your newly created sub site.

sub-site in SharePoint 2013
Advertisements

Introduction

This article provides a Requester monitoring list that is easy enough to do in SharePoint. The 3 statuses are an easy visual way of seeing what status each of the requesters was on. The statuses used in this list are:

  1. Approved
  2. Rejected
  3. Pending

These values are populated from a Choice field in the list, but as you can see from the before image below it is not that easy to quickly and easily see what level each of the Requesters are on.

Requester

On the Edit page, select the Insert Web Part tab from the Ribbon. From the Categories menu, select Media and Content and then Script Editor from the Parts menu:

Script Editor

Click on the Add button at the bottom of the page to install the Web Part.

Embedding Code to Your Site

  • Once the Web Part has been successfully installed on your page, you will see a hyperlink button under the Script Editor labelled EDIT SNIPPET. Click the EDIT SNIPPET link to insert HTML/Script code:

    <script type=”text/javascript” src=”//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js”></script>

    <script type=”text/javascript”>

        $(document).ready(function () {

            $Text = $(“td.ms-cellstyle.ms-vb2:contains(‘Approved’)”); $Text.parent().css(“background-color”, “#01DF3A”);

            $Text = $(“td.ms-cellstyle.ms-vb2:contains(‘Rejected’)”);

            $Text.parent().css(“background-color”, “#F90101”);

            $Text = $(“td.ms-cellstyle.ms-vb2:contains(‘Pending’)”);

            $Text.parent().css(“background-color”, “#EAC117”);

        });

    </script>

    Script code

  • After you have inputted the appropriate code in the Embed dialog box, click Insert to save the HTML/Script.

Below you can see the end result with some data entered and various names against various action statuses:

action Status

In this article we need to pass the user profile information, let’s say Account Name, First Name, Last Name, PictureUrl and SPS-SipAddress and so on to some other function in JavaScript. For accessing the current logged in user information you need to call the GetUserProfileByName function of the userprofileservice web service.

I have written a JavaScript code for accessing the GetUserProfileByName function of the userprofileservice web service:

function fetchUserProfileData() {

var art = null;

//IE

if (window.ActiveXObject) {

art = new ActiveXObject(“Microsoft.XMLHTTP”);

}//Mozilla, chrome, etc.,

else if (window.XMLHttpRequest) {

art = new XMLHttpRequest();

}

else {

throw new Error(“XMLHttpRequest not supported”);

}

if (art == null) return null;

art.Open(“POST”, _spPageContextInfo.webAbsoluteUrl+ “/_vti_bin/userprofileservice.asmx“, false);

art.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8”);

art.setRequestHeader(“SOAPAction”, http://microsoft.com/webservices/SharePointPortalServer/UserProfileService/GetUserProfileByName&#8221;);

var Xsoap = “<?xml version=\”1.0\” encoding=\”utf-8\”?><soap:Envelope xmlns:soap=\”http://schemas.xmlsoap.org/soap/envelope/\” xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\” xmlns:xsd=\”http://www.w3.org/2001/XMLSchema\” xmlns:tns=\”http://schemas.microsoft.com/sharepoint/soap/\”><soap:Body><GetUserProfileByName xmlns=\”http://microsoft.com/webservices/SharePointPortalServer/UserProfileService\”><AccountName>Domain\\UserName</AccountName></GetUserProfileByName></soap:Body></soap:Envelope>”;

art.Send(Xsoap);

var xmlDoc = art.responseXML;

var strAccountSPSHireDate = “”;

var elmValue = xmlDoc.getElementsByTagName(“Value”);

for (i = 0; i < elmValue.length; i++) {

if (elmValue[i].parentNode.parentNode.parentNode.childNodes[2].text ==‘SPS-HireDate

‘) {

strAccountSPSHireDate = elmValue[i].childNodes[0].nodeValue;

}

}

alert(strAccountSPSHireDate);

}

List of User Properties

AccountName
DirectReports
DisplayName
Email
ExtendedManagers
ExtendedReports
IsFollowed
LatestPost
Peers
PersonalUrl
PictureUrl”
Title
UserProfileProperties
UserUrl

List of User Profile Properties

AboutMe
SPS-LastKeywordAdded
AccountName
SPS-Locale
ADGuid
SPS-Location
Assistant
SPS-MasterAccountName
CellPhone
SPS-MemberOf
Department
SPS-MUILanguages
EduExternalSyncState
SPS-MySiteUpgrade
EduOAuthTokenProviders
SPS-O15FirstRunExperience
EduPersonalSiteState
SPS-ObjectExists
EduUserRole
SPS-OWAUrl
Fax
SPS-PastProjects
FirstName
SPS-Peers
HomePhone
SPS-PersonalSiteCapabilities
LastName
SPS-PersonalSiteInstantiationState
Manager
SPS-PhoneticDisplayName
Office
SPS-PhoneticFirstName
PersonalSpace
SPS-PhoneticLastName
PictureURL
SPS-PrivacyActivity
PreferredName
SPS-PrivacyPeople
PublicSiteRedirect
SPS-ProxyAddresses
QuickLinks
SPS-RegionalSettings-FollowWeb
SID
SPS-RegionalSettings-Initialized
SISUserId
SPS-ResourceAccountName
SPS-AdjustHijriDays
SPS-ResourceSID
SPS-AltCalendarType
SPS-Responsibility
SPS-Birthday
SPS-SavedAccountName
SPS-CalendarType
SPS-SavedSID
SPS-ClaimID
SPS-School
SPS-ClaimProviderID
SPS-ShowWeeks
SPS-ClaimProviderType
SPS-SipAddress
SPS-ContentLanguages
SPS-Skills
SPS-DataSource
SPS-SourceObjectDN
SPS-Department
SPS-StatusNotes
SPS-DisplayOrder
SPS-Time24
SPS-DistinguishedName
SPS-TimeZone
SPS-DontSuggestList
SPS-UserPrincipalName
SPS-Dotted-line
SPS-WorkDayEndHour
SPS-EmailOptin
SPS-WorkDayStartHour
SPS-FeedIdentifier
SPS-WorkDays
SPS-FirstDayOfWeek
Title
SPS-FirstWeekOfYear
UserName
SPS-HashTags
UserProfile_GUID
SPS-HireDate
WebSite
SPS-Interests
WorkEmail
SPS-JobTitle
WorkPhone
SPS-LastColleagueAdded

Summary

We explored how to get the user profile property value using JavaScript and SharePoint services.

This article shows how to add a user in a SharePoint 2010 site programmatically. Here we have a Group already defined in that site, we select the user name from a dropdown selection to add a user to the selected group. This shows the details of a generic function in which you pass the group name and user name, then the function will add the user into the group.

<div class=”announcements_detail”>

    <h2>

        Add User To Group</h2>

    <div class=”rows firstRow”>

        <div class=”col1″>

            User Name:</div>

        <div class=”col2 title”>

            <div class=”inner_col2″>

                <div class=”user_detail”>

                    <SharePoint:PeopleEditor ID=”PplEdtor” runat=”server” AllowEmpty=”true”
                        MultiSelect=”false”

                        SelectionSet=”User” ValidatorEnabled=”true” />

                </div>

            </div>

        </div>

        <div class=”clr”>

        </div>

    </div>

    <div class=”rows”>

        <div class=”col1″>

            Groups:</div>

        <div class=”col2″>

            <div class=”inner_col2″>

                <asp:DropDownList ID=”ddlGroups” runat=”server”>

                </asp:DropDownList>

                <asp:RequiredFieldValidator ID=”reqGroups” runat=”server”
                    ErrorMessage=”Please select Group” ControlToValidate=
“ddlGroups”
 InitialValue=””></asp:RequiredFieldValidator>

            </div>

        </div>

        <div class=”clr”>

        </div>

    </div>

    <div class=”rows noBorder”>

        <div class=”col1″>

        </div>

        <div class=”col2 noBg”>

            <div class=”inner_col2″>

                <asp:Button ID=”bntAddUserToGrp” runat=”server” Text=”Add User”
                    class=”green_gradient_bg”

                    OnClick=”btnAddUserToGrp_Click”></asp:Button></div>

        </div>

        <div class=”clr”>

        </div>

    </div>

    <div>

        <input class=”close_btn” id=”btnClose” onclick=”javascript:window.close();”
          type=”button” />

    </div>

</div>

The following is the code to show how to add a user to a SharePoint group.

protected void Page_Load(object sender, EventArgs e)
{
try

{
if
(!Page.IsPostBack)
{
BindGroupsWithDropDownList();
}
}
catch
(Exception ex)
{
ShowError(“Page_Load: “ + ex.Message);
return
;
}
}
private
void BindGroupsWithDropDownList()
{
try

{
ddlGroups.Items.Clear();
string
[] strGroupArr = { “ParticipantGroupName”, “MentorGroupName”, “SponsorGroupName”, “BusinessGroupName” };
foreach
(string strGroupType in strGroupArr)
{
ddlGroups.Items.Add(strGroupType);
}
}
catch
(Exception ex)
{
ShowError(“BindGroupData: “ + ex.Message);
}
}
protected
void btnAddUserToGrp_Click(object sender, EventArgs e)
{
bool
Flag = false;
string
strMsg = string.Empty;
try

{
if
(PplEdtor.IsValid)
{
string
strUsers = GetMembersFromPeoplePicker(PplEdtor);
string
strParticipant = SPContext.Current.Web.AllUsers[strUsers].ID + “;#” + strUsers;
string
strGroupName = ddlGroups.SelectedItem.ToString().Trim();
string
strGrouptyp = ddlGroups.SelectedValue.ToString().Trim();

            if (!string.IsNullOrEmpty(strUsers) && !string.IsNullOrEmpty(strGroupName) && !string.IsNullOrEmpty(strGrouptyp))
{
string
strSiteUrl = SPContext.Current.Web.Url;
SPSecurity
.RunWithElevatedPrivileges(delegate()
{
using
(SPSite oAdminSite = new SPSite(strSiteUrl))
{
using
(SPWeb oAdminWeb = oAdminSite.OpenWeb())
{
if
(AddUserToGroup(oAdminWeb, strUsers, strGroupName))
{
Flag = true;
}
else

{
strMsg = “User NOT added to group”;
}
}
}
});
strMsg = “User added to group successfully”;
}
else

{
strMsg = “Parameters Missing, to add a user!!!”;
}
}
else

{
strMsg = “Please enter valid User Name”;
}
ScriptManager
.RegisterStartupScript(this, this.GetType(), “starScript”, “showMessage(‘” + strMsg + “‘);”, true);
}
catch
(Exception ex)
{
ShowError(“btnAddUserToGrp_Click: “ + ex.Message);
return
;
}
}
public
bool AddUserToGroup(SPWeb oWeb, string strUserNameToAdd, string strGroupName)
{
try

{
bool
Flag = false;
oWeb.AllowUnsafeUpdates = true;
SPUser
spUser = oWeb.EnsureUser(strUserNameToAdd);
if
(spUser != null)
{
SPGroup
spGroup = oWeb.Groups[strGroupName];
if
(spGroup != null)
spGroup.AddUser(spUser);
}
oWeb.Update();
Flag = true;
oWeb.AllowUnsafeUpdates = false;
return
Flag;
}
catch
(Exception ex)
{
oWeb.AllowUnsafeUpdates = false;
return
false;
}
}
private
string GetMembersFromPeoplePicker(PeopleEditor oPeopleEditor)
{
try

{
string
strLoginNames = string.Empty;
foreach
(PickerEntity oUser in oPeopleEditor.Entities)
{
if
(oUser.IsResolved)
strLoginNames += (string.IsNullOrEmpty(strLoginNames)) ? oUser.Key : “;” + oUser.Key;
}
return
strLoginNames;
}
catch
(Exception ex)
{
ShowError(“GetMembersFromPeoplePicker: “ + ex.Message);
return
string.Empty;
}
}
private
void ShowError(string strMsg)
{
Response.Write(“<br />” + strMsg);
}

Introduction

This is a quick tutorial covering how to clear your SPD 2013 Cache. That is handy, especially when working with SPD 2010 and SPD 2013.  Clearing the cache will remove any of your past connection history as well provide you a “clean slate” to work from.  The cache is not even cleared after doing a reinstall, so this really is the only way to clear it.

Versioning with check-in/out are great but not always preferred, and certainly not infallible. As I learned on a project a few years ago that recently bit me again when my new machine was not similarly configured, SharePoint Designer has a dirty little habit of caching files, including say the XML/XSLT, JS and CSS you might be working with on your site.

No need to fret though; buried in the settings of each version is a toggle that will ensure SPD never sets you back by loading a cached file.

Procedure:

  1. Close SPD if it is open
  2. Open My Computer

    a.Click the address bar

  3. Paste in:
    %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
  4. Delete everything within this location
  5. Click the address bar
  6. Paste in:
    %APPDATA%\Microsoft\Web Server Extensions\Cache
  7. Delete everything in this location

SharePoint Designer 2010 and 2013

  1. Navigate to the “File” menu then select “Options” -> “General” -> “Application Options”.
  2. On the “General” tab, under the “General” heading, uncheck “Cache site data across SharePoint Designer sessions”.

SharePoint Designer

This is a quick couple of steps for clearing your cache and to hopefully resolve SharePoint Designer anomalies that present themselves from time to time.

Introduction

SharePoint 2013 is all about JavaScript. JavaScript CSOM is greatly improved and enhanced, SharePoint Apps are essentially JavaScript-based, Client-Side Rendering is now the main rendering technique for all SharePoint lists (well, except for Survey and Calendar lists), JSGrid is used for list edit mode, and many many other things.

Yes, JavaScript won, so now we, SharePoint developers, need to deal with it much more often than we used to.

Script#

People noticed drawbacks of JS long ago. To smooth them out, projects like Script# and GWT were created. The idea is basically to compile a normal language like C# into JavaScript code; this is exactly what Script# does.

And it works well enough! Script# has been used by Microsoft itself for some big projects, like Office Web Apps, Bing Maps, and by pure happenstance, for SharePoint JavaScript Object Model (JSOM)! Can you believe that? But yes, it’s true, the majority of js files you will find in hive 15 were generated by Script#.

Yes, Script# works very well, unless you must use some existing JS libraries. In this case, you need definitions that would contain information about types of variables, parameters, methods, and so on. Unfortunately, no Script# definitions for SharePoint is available. And creating them by hand is a very tedious work, trust me. But wait, if SharePoint JSOM is written in Script# then something.

TypeScript

Not so long ago, another project has been started by Microsoft, TypeScript. Unlike Script# and GWT that use existing languages (C# and Java) as the source, TypeScript is a new language. But the thing is, TypeScript is a superset of JavaScript! So any existing JS can be compile into TypeScript without errors (at least this is the theory, in practice I know there are some exceptions to this rule).

Support of TypeScript is broad, the community is passionate and TypeScript definitions for many and many JS libraries have already been created. The largest collection of them (the DefinitelyTyped project) includes definitions for 130 libraries!

The TypeScript compiler is opensource and is written in JavaScript, and this means that we can have TypeScript intellisense right in the browser.

In sum, TypeScript is definitely promising. And even better, now you can use it with SharePoint!

Create high-quality strongly-typed and even half-documented definitions that cover a great deal of the SharePoint JavaScript API (and we plan to add even more definitions in the next releases).

Currently, we have the following things covered:

  1. Client-side Object Model (CSOM) core classes
    • SP namespace (ready)
    • SP.WebParts (ready)
    • SP.SOD (ready)
  2. Social object library
    • SP.Sharing (ready)
    • SP.UserProfiles (ready)
    • SP.Social (ready)
  3. SharePoint Client-side Rendering (CSR)
    • SPClientTemplates (ready)
  4. Workflows
    • SP.Workflow (ready)
    • SP.WorkflowServices (ready)
  5. SharePoint UI elements:
    • SP.UI.Notify (ready)
    • SP.UI.Status (ready)
    • SP.UI.Menu (ready)
    • SP.UI.ModalDialog (ready)
    • SP.UI.ApplicationPages: some useful stuff here nobody knows about, for example ClientPeoplePickerWebServiceInterface! (ready)
    • CalloutManager (ready)
  6. SharePoint Search
    • Microsoft.SharePoint.Client.Search (ready)
  7. Business Connectivity Services
    • SP.BusinessData (ready)
  8. SharePoint Managed Metadata
    • SP.Taxonomy (ready)

Basically this means that now you and we, all of us, can use TypeScript when working with SharePoint JavaScript, and benefit from strong typing and intellisense.

The project also includes many examples written in TypeScript and a couple of extensions. Please, visit the project site on CodePlex to determine more:

SharePoint 2013 TypeScript Definitions

TypeScript Important Links

The following procedure shows how to create a sub-site in SharePoint 2013.

Step 1

Log into your SharePoint 2013 site.

Step 2

Click on the “Settings” icon and choose “Site Contents” from the drop-down menu.

 sub-site in SharePoint 2013

Step 3

At the bottom of the page, click on “new subsite” under the “Subsites” header.

 sub-site in SharePoint 2013

Step 4

Enter the “Title” and “Description” of your new subsite, choose the URL for it and select a template for this subsite.

 sub-site in SharePoint 2013

Step 5

Select the necessary permission and navigation settings and click “Create.”

 sub-site in SharePoint 2013

Step 6

Now you can see your newly created sub site.

sub-site in SharePoint 2013