Friday, 13 June 2014
Get List Field Internal Name
You can get the internal name for a column by browsing to the List Settings > Edit Column and look at the QueryString. This will be url encoded but is a simple way of retrieving the internal name without writing any code. You will get something like:
/_layouts/FldEdit.aspx?List=%7B37920121%2D19B2%2D4C77%2D92FF%2D8B3E07853114%7D&Field=Product%5Fx0020%5FDescription
%5F is a '_'. The field name is Product_x0020_Description.
The code option is to use:
string itemInternalName = item.Fields["Field Display Name"].InternalName;
Thursday, 12 June 2014
Different ways to get user name using javascript
Get user email
_spPageContextInfo.userLoginName
Using REST Service
$(document).ready(function () {
var userid = _spPageContextInfo.userId;
function GetCurrentUser() {
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var requestHeaders = { "accept" : "application/json;odata=verbose" };
$.ajax({
url : requestUri,
contentType : "application/json;odata=verbose",
headers : requestHeaders,
success : onSuccess,
error : onError
});
}
function onSuccess(data, request){
//var loginName = data.d.LoginName.split('|')[1];
var loginName = data.d.Title;
alert(loginName);
}
function onError(error) {
alert(error);
}
GetCurrentUser();
});
Using JSOM
$(document).ready(function () {
var currentUser;
// Ensure that the SP.js is loaded
if (SP.ClientContext != null) {
SP.SOD.executeOrDelayUntilScriptLoaded(getCurrentUser, 'SP.js');
}
else {
SP.SOD.executeFunc('sp.js', null, getCurrentUser);
}
function getCurrentUser() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
currentUser = web.get_currentUser();
context.load(currentUser);
context.executeQueryAsync(onSuccessMethod, onRequestFail);
}
function onSuccessMethod(sender, args) {
var account = currentUser.get_loginName();
var currentUserAccount = account.substring(account.indexOf("|") + 1);
alert(currentUserAccount);
}
// This function runs if the executeQueryAsync call fails.
function onRequestFail(sender, args) {
alert('request failed' + args.get_message() + '\n' + args.get_stackTrace());
}
});
Tuesday, 27 May 2014
SharePoint 2013: Get UserProfile Properties with REST API
Thanks to
http://www.vrdmn.com/2013/07/sharepoint-2013-get-userprofile.html
1) Get all properties of current user:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties2) Get single property of current user:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties/PictureUrlOR
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl
3) Get Multiple Properties for the current user:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl,AccountName4) Get all properties of Specific User:
For Office 365/SharePoint Online:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|vardhaman@siteurl.onmicrosoft.com'
For SharePoint 2013 On-Premise:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='domain\username'
5) Get Specific UserProfile Property of Specific User:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='i:0%23.f|membership|vardhaman@siteurl.onmicrosoft.com'
For SharePoint 2013 On-Premise:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName='LastName')?@v='domain\username'
6) Get Multiple UserProfile Properties for Specific User:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertiesFor
Sunday, 18 May 2014
My validators are not working
This was working
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>
...
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>
As soon as I changed it to
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>
...
</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>
...
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>
As soon as I changed it to
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup">
</asp:RequiredFieldValidator>
...
<!--
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ForeColor="Red" ErrorMessage="* This field cannot be blank." ControlToValidate="FunctionGroup"></asp:RequiredFieldValidator>
-->
it stopped working. So if you don't want to use validator, instead of commentting out it, delete it.
Thursday, 1 May 2014
SharePoint Search REST API not returning all subsites
This query is not working !!! I have 10 subsites, but it only returns 2 of them.
https://serverURL/_api/search/query?querytext='path:"*********" contentclass:STS_Web'&rowlimit=20
Solution is to add &trimduplicates=false at the end of the query.
https://serverURL/_api/search/query?querytext='path:"*********" contentclass:STS_Web'&rowlimit=20&trimduplicates=false
https://serverURL/_api/search/query?querytext='path:"*********" contentclass:STS_Web'&rowlimit=20
Solution is to add &trimduplicates=false at the end of the query.
https://serverURL/_api/search/query?querytext='path:"*********" contentclass:STS_Web'&rowlimit=20&trimduplicates=false
SharePoint Designer Cache Locations
- %APPDATA%\Microsoft\Web Server Extensions\Cache
- %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
Monday, 7 April 2014
XmlDocument.CreateElement automatically adds xmlns="". How to get ride of it?
Problem:
Solution:
When creating the url element, instead of using
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url xmlns="">
.......................
</url>
</urlset>
Solution:
When creating the url element, instead of using
doc.CreateElement("url");
use doc.CreateElement("url","http://www.sitemaps.org/schemas/sitemap/0.9");
Subscribe to:
Posts (Atom)