How check page level permission on SharePoint pages library using JSOM
Hi,
Can anyone tell me how check page level permission on SharePoint pages library using JSOM.
Tanks in advance .
Regards,
Hari
Regards, Hari
Hi,
According to your post, my understanding is that you want to check the page level permission on SharePoint Pages library via JSOM.
I have made a simple code demo to check whether current user has edit permission for the pages in Pages library, it works like a charm.
You can re-write it to fit your environment.
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
var web;
var list;
$(function(){
$("#Button1").click(function()
console.log(1);
getListItems('Pages',success_Items,error_Items);
console.log(2);
function getListItems(listTitle,success,error)
var context = SP.ClientContext.get_current();
this.web = context.get_web();
this.list = context.get_web().get_lists().getByTitle(listTitle);
this.items = list.getItems(SP.CamlQuery.createAllItemsQuery());
this._currentUser = web.get_currentUser();
context.load(this._currentUser);
context.load(web,'EffectiveBasePermissions');
context.load(items);
context.executeQueryAsync(
function() {
success(items);
error
function success_Items(items){
var e = items.getEnumerator();
while (e.moveNext()) {
this.item = e.get_current();
console.log(this.item.get_item('FileLeafRef')); //print File or Folder Name
console.log(this.item.get_item('FileRef')); //print File or Folder Url
if (this.web.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems)) {
console.log('Nice, edit list item permissions!');
else {
console.log('Boo, no edit list item permissions!');
function error_Items(sender,args){
console.log(args.get_message());
</script>
<input id="Button1" type="button" value="Check Permissions"/>
Thanks & Regards,
Jason
Jason Guo
TechNet Community Support
Similar Messages
-
How to add js files to sharepoint page using sharepoint designer
how to add js files to sharepoint page using sharepoint designer
Upload the files to your site collection into the site assets library or into the style library, depending on perference.
Then you can include the JS files either in the master page, page tempalte or using web parts. -
How to grant anonymous access on sharepoint document library/list only not for web application
Hello
How to grant anonymous access on sharepoint document library/list only not for web application.I have claim based sharepoint site and has to be but i want to grant access on document library/list only.Is this possible?
Thanks
Rajesh Kumar "Changing the Face" can change nothing.But "Facing the Change" can change everything.As i am using following code
SPSite site = SPContext.Current.Site;
SPWeb web = SPContext.Current.Web;
SPSecurity.RunWithElevatedPrivileges(delegate()
using (SPSite ospSite = new SPSite(site.ID))
using (SPWeb webs = ospSite.OpenWeb(web.ID))
// Enable anonymous access on web application
webs.AllowUnsafeUpdates = true;
SPUrlZone urlZone = SPUrlZone.Default;
SPWebApplication specifiedWebApplication = ospSite.WebApplication;
SPIisSettings iisSettings = specifiedWebApplication.IisSettings[urlZone];
//iisSettings.AuthenticationMode = AuthenticationMode.Windows;
iisSettings.AllowAnonymous = true;
specifiedWebApplication.Update();
// Get document library collection here and fetch all the document urls
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["Documents"];
if (docLib != null)
docLib.BreakRoleInheritance(true, false);
docLib.AllowEveryoneViewItems = true;
docLib.AnonymousPermMask64 = SPBasePermissions.ViewPages | SPBasePermissions.OpenItems | SPBasePermissions.ViewVersions
| SPBasePermissions.Open | SPBasePermissions.UseClientIntegration | SPBasePermissions.ViewFormPages | SPBasePermissions.ViewListItems;
//docLib.AnonymousPermMask64 = SPBasePermissions.EmptyMask;
docLib.Update();
Should working but getting access denied......i am totally stuck at this point.
Rajesh Kumar "Changing the Face" can change nothing.But "Facing the Change" can change everything. -
Set rating settings in Sharepoint library using JSOM api.
Is it possible to set rating settings in Sharepoint library using JSOM api/ Client side?
Ashish Baranwal || To know what you know and what you do not know, that is true knowledgeHI,
Please check the below url for reference.
https://social.msdn.microsoft.com/Forums/office/en-US/5069c9b8-7427-4749-bd98-cfc0f492c3a2/how-to-enable-ratings-on-sharepoint-list-using-client-object-model-for-office-365-sharepoint-site?forum=sharepointdevelopment
https://samlman.wordpress.com/2015/03/02/how-to-use-csom-with-ratings-in-sharepoint-2013/
Don't forget to mark it as an Answer if it resolves your issue and Vote Me as helpful if it useful.
Mahesh -
Download older version of a file from SharePoint Document Library using CSOM and 404 error
Hi,
I am trying to download previous versions including Major and Minor versions of documents from SharePoint Online using CSOM. I get 404 error when I try to download the file. I found several posts on various discussion forums where people are getting same
error but none of those have any solution/answer. Below is one of the threads and sample code I have tried that results in 404 error. If I use the link in browser directly, I am able to download the file. Also I am able to download the current version of file
using CSOM without any problem, it is only the older versions that give me 404 in CSOM.
http://qandasys.info/how-to-download-the-historical-file-version-content-using-csom/
public int GetStreamFromFile(string docid, string lib, string fileurl, ClientContext clientContext, int iuserid, string Version, bool isCurrrent)
if(!isCurrent)
List LibraryName = clientContext.Web.Lists.GetByTitle(lib);
clientContext.Load(LibraryName);
clientContext.ExecuteQuery();
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "" + fileurl +
Microsoft.SharePoint.Client.ListItemCollection collListItem = LibraryName.GetItems(camlQuery);
clientContext.Load(collListItem, items => items.Include(item => item.Id, item => item["FileLeafRef"], item => item["LinkFilename"],
item => item["FileRef"], item => item["File_x0020_Size"], item => item["DocIcon"], item => item.File.Versions));
//clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem oListItem in collListItem)
//string fileurl1 = (string)oListItem["FileRef"];
//string filename = (string)oListItem["LinkFilename"];
foreach (FileVersion version in oListItem.File.Versions)
if (Version == version.VersionLabel)
//Added excutequery to get object one more time as per blog
//http://social.technet.microsoft.com/Forums/de-DE/sharepointdevelopmentprevious/thread/88a05256-8694-4e40-863d-6c77512e079b
clientContext.ExecuteQuery();
FileInformation fileInformation = ClientOM.File.OpenBinaryDirect(clientContext,version.Url);
bytesarr = ReadFully(fileInformation.Stream);
DarwaishHi,
According to your description,
I know you want to get older version of a file from SharePoint Document Library using Client Object Model.
The following code snippet for your reference:
public void GetVersions()
ClientContext clientContext = new ClientContext(“http://SPSite”);
Web site = clientContext.Web;
clientContext.Load(site);
clientContext.ExecuteQuery();
File file = site.GetFileByServerRelativeUrl(“/Shared Documents/mydocument.doc”);
clientContext.Load(file);
clientContext.ExecuteQuery();
ListItem currentItem = file.ListItemAllFields;
clientContext.Load(currentItem);
clientContext.ExecuteQuery();
FileVersionCollection versions = file.Versions;
clientContext.Load(versions);
clientContext.ExecuteQuery();
if (versions != null)
foreach(FileVersion _version in versions)
Console.WriteLine(“Version : {0}”,_version.VersionLabel);
More information:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.file.versions.aspx
Best Regards,
Dennis Guo -
Workflow for Changing Item Level Permission in SharePoint 2013 (Office365)
I am using OOTB Tasks List in SharePoint 2013 (O365). Now my scenario is like this:
I have two user groups: 1.Sales Managers 2. Sales Executives
Sales Managers can create & assign task to Executive. I want something like Sales Managers Can view all tasks (Which is by default view of tasks list i.e. perfact) but Executives can see only their tasks assigned to them. How can I achive this?
Can I use WorkFlow for this to Change item level permission or to assign permission to assigned to user? or JS
Can anyone have proper solution? thanks1. make 2 SharePoint group 1>Sales Managers 2>Sales Executives
2. Show 2 WP of same task list in same page.
3. Use Audience Target for Sales Managers Sharepoint group in first Webpart property. (All
Iten view)
4. Show "My Task" view (assign to =[Me]) Bottom WP for same task list and use Audience Target for Sales Executives. Or if you want it to see
Sales Managers as well, the dont use any Audience Target.
Bottom line - SharePoint group use in Audience Target will do the trick. OOTB
Regards Sudip Misra [email protected] +1-412-237-5435 Pittsburgh, PA -
Item level permission on workflow task List using sharepoint designer 2013
Hello All,
I have created a custom approval workflow. Workflow create a Task in Tasks List. Now suppose A task is assign to user1.
User2 should not able to edit\approve\reject the item.
How to give item level permission using SharePoint designer in SharePoint 2013 workflow.
SharePoint 2013 workflow doesn't have impersonation steps also.
Please suggest how to give permission on task list based on assigned To field.In order to change permissions on a list item you'd need a sharepoint 2010 workflow according to http://msdn.microsoft.com/en-us/library/jj728659.aspx
Unfortunately this functionality is not available in SharePoint 2013 workflows :-(
The impersonation step still exists, but it is now called "App Step" in the SharePoint Designer 2013 Ribbon. This step is disabled, though, until you activate a web site feature called "Workflows can use app permissions" -
How to create different Graphs in SharePoint 2013 without using Excel service?
Hi All,
I want to create different graphs in SharePoint without using Excel Service.
I do not want to create excel and then upload that to SharePoint.
Any one knows how to do that? Isthere any option to do that?
Thanks in AdvanceHi Darsh,
You can use
SharePoint chart webpart to display charts. Or you can use any jQuery charting library and feed data using JSOM or REST. Ex. high charts:
http://www.highcharts.com/products/highcharts
http://office.microsoft.com/en-us/sharepoint-server-help/sharepoint-lists-vi-exciting-ways-to-display-your-list-data-RZ102425636.aspx?section=3
Best Regards,
Brij K -
How to create a 'Link to a Document' Item in a SharePoint Document Library using power shell?
Hi,
I have a document library with "Link to a document" content type. And, I have to add some links into that library using powershell. I have searched enough regarding approachs for adding a link into the library in powershell but i did not get anything yet.
Please provide some approaches and code samples to solve this problem.
Thanks,
Lalit Kumar MishraAdding Site Columns To Content Types Using PowerShell
Adding Site Columns To Content Types Using PowerShell
The below PowerShell script will allow you to add a metadata field that is either contained at the Site Collection level, Site level, or library level, to the specified Content Type.
It also contains some optional lines that you might choose to include or exclude, such as
Setting the visibility of the column in the edit form to hidden
Setting the status of the column to require values
01
function Add-SPContentTypeField
02
03
<#
04
.Synopsis
05
This function will allow you to add a library field to a Content
Type
06
.Description
07
This function will add the nominated site column/ library column to a nominated Content
Type within all of the 'Document Libraries'
in the given Site Collection
08
.Example
09
C:\PS>Add-SPContentTypeField
–SiteUrl “http://yourdomain.com/sites/Finance –FieldName
"myField" -CTypeAddedTo "myContentType"
10
.Notes
11
Name: Add-SPContentTypeField
12
Author: Petro Margaritis
13
Last Edit: 19/07/2012
14
Keywords: Fields, Site Columns, Content Types
15
.Link
16
http://thesharepointproject.com/
17
#>
18
19
Param (
20
[parameter(Mandatory=$true)][string]$SiteUrl,
21
[parameter(Mandatory=$true)][string]$FieldName,
22
[parameter(Mandatory=$true)][string]$CTypeAddedTo
23
24
25
$site = Get-SPSite
$SiteUrl
26
27
# Walk through each site in the site collection
28
$site | Get-SPWeb
-Limit all | ForEach-Object {
29
30
write-host
"Checking site:"$_.Title -Foregroundcolor
Green
31
32
# Go through each document library in the site
33
foreach
($list in $_.Lists | where
{ $_.BaseTemplate -eq "DocumentLibrary" })
34
35
36
# Check to see if the library contains the content type we are looking for
37
if (($list.ContentTypes |
where { $_.Name -eq $CTypeAddedTo
}) -eq $null)
38
39
Write-Host
"The Content:" $CTypeAddedTo "does not exist in the library:"
$list.Title -Foregroundcolor Red
40
41
else
42
43
# Check to see if the library contains the field we are looking for
44
if (($list.Fields |
where { $_.Title -eq $FieldName
}) -ne $null)
45
46
# Get the content type you want to add the field to
47
$ct
= $list.ContentTypes[$CTypeAddedTo]
48
# Get the column you want to copy
49
$field
= $list.Fields[$FieldName]
50
# Add the column to the content type
51
$ct.Fieldlinks.Add($field)
52
$ct.update()
53
54
# Add additional column settings
55
$ctFieldLinks
= $ct.FieldLinks | Where
{$_.Name -eq $field.Title}
56
# OPTIONAL: This will set the column to hidden so that it is not viewable in the edit form
57
$ctFieldLinks.Hidden =
$true
58
# Set Field to require value
59
$ctFieldLinks.Required =
$true
60
$ct.Update()
61
Write-Host
"The Field:" $field.Title "has been successfully added to the library:"
$list.Title -Foregroundcolor Cyan
62
63
else
64
65
Write-Host
"The Field:" $FieldName "does not exist in the library:"
$list.Title -Foregroundcolor Yellow
66
67
68
69
70
# Dispose of the site object
71
$site.Dispose()
72
Simply copy and paste the above into Notepad and save it as a PowerShell file with the name
Add-SPContentTypeField.ps1
view sourceprint?
1
# To run the above function you'll need to do the following - go into the saved location
2
Cd C:\scripts\
3
# Then call it using the dot prefix - note that there is a space between the dots, ..\
4
. .\Add-SPContentTypeField.ps1
5
# Now we can happily run the script like so
6
Add-SPContentTypeField –SiteUrl “http://yourdomain.com/sites/Finance –FieldName
"myField" -CTypeAddedTo "myContentType" -
I have been asked to see if it would be possible to get exchange emails downloaded and or sent to a document library .
I know of the sitemail box app. but we are not running Exchange 2013.
and setting up the lists and or document library to receive emails using the built in doesn't seem to be working...( maybe not configured correctly, i would need to see what the prior admin/developer did)
But is there a way to get the emails downloaded to a document library using a workflow and or a powershell script that is triggered via workflow?Hi,
Since workflow can only work on items in SharePoint sites, they cannot get Exchange emails, let alone download emails to SharePoint library. However, you could manually save email to local and upload it to SharePoint list/library.
I'd suggest you toubleshooting the incoming email settings in SharePoint. Please refer to the article below and check your configuration:
https://technet.microsoft.com/en-us/library/cc262947.aspx
http://blogs.technet.com/b/harmeetw/archive/2012/12/29/sharepoint-2013-configure-incoming-emails-with-exchange-server-2013.aspx
Regards,
Rebecca Tu
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
How do you connect ipad 2 to itunes library using home sharing
How do you connect the ipad 2 to the itunes library using home sharing so you can listen on your ipad 2? I've seen directions for the ipad which tell you how to setup home sharing then open ipod and touch library in the left column, but when I hit library, nothing happens. I'm assuming the ipad 2 has something different about it. Any help would be greatly appreciated.
Thanks.
PS, the OS is 4.3.3 (just got it but it's not on the os list)See iTunes 9- Understanding Home Sharing and iTunes- Troubleshooting Home Sharing. Also, open iTunes, select iTunes Help from the Help menu and search for "home shar."
-
Get the item level permission in sharepoint 2013 uisng rest api
I created the test list and i created the 5 items in that list.
I stopped the item level permissions.
I shared the list item with userA.
In the rest api response, it giving the other users also (means user who is not having permission to the item).
I am using below rest query
/_api/Web/GetFileByServerRelativeUrl('/site/Lists/test/1_.000')?$expand=Versions,Author,ModifiedBy,ListItemAllFields/RoleAssignments/Member/Users,ListItemAllFields/FieldValuesAsText,ListItemAllFields/ParentListHi,
Following are the steps, I performed:
After adding the item in the list, I went into list item permissions and clicked on stop item permissions. Then I selected all the permissions which got carried over to the item and clicked on "Remove user permissions" in the ribbon. After that
I clicked on Grant permissions in the ribbon and shared the item with one user. Note that last action can also be performed by going back into the list and selecting the item and click on Share.
Finally, I ran the above REST query and returned the user with whom the item was selected and also the system account (which is expected, as admin will have access.
You can try shortening your query as well
/_api/Web/GetFileByServerRelativeUrl('/site/Lists/test/1_.000')?$expand=ListItemAllFields/RoleAssignments/Member/Users
This will return the relevant user permissions and response will contain lesser data and hence will be easier to read. Lastly, try intercepting the traffic
using fiddler, as again it will in reading the response.
Thanks,
Nadeem
Please remember to up-vote or mark the reply as answer if you find it helpful. -
How to filter the Files from SharePoint Document Library based upon cloumn value
Hi
I should filter the files from document library. I have column called "Print Status" for the document library the value would be either "Yes" or "No".
Now i should filter out the files which has "Print Status" as a "Yes".
I am using SPFolder and SPFile from SharePoint Object Model to traverse the file in doc library.
How could i do it?
My Sample code:
foreach (SPFolder childFolder in folder.SubFolders)
if (childFolder.Name != "Forms")
AspControls.TreeNode trn = new System.Web.UI.WebControls.TreeNode(childFolder.Name, "", "~/_layouts/images/itdl.gif", childFolder.ServerRelativeUrl.ToString(), "");
newNode = TraverseFiles(childFolder, trn);
// add the new node to the tree
rootNode.ChildNodes.Add(newNode);
// loop through the files
foreach (SPFile childFile in folder.Files)
// create a new node and add to the tree
AspControls.TreeNode childNode = new System.Web.UI.WebControls.TreeNode(childFile.Name + " (" + childFile.TimeLastModified.ToShortDateString()
+ ")", Convert.ToString(childFile.Item["ID"]), "~/_layouts/images/" + childFile.IconUrl, childFile.ServerRelativeUrl.ToString(), "");
rootNode.ChildNodes.Add(childNode);
Thanks
Poomani Sankaran.Why do you transvers the file an not use a camp query? In a CAML query you can filter the print status and are able to get all files and folder objects at once.
Check out the following post: http://social.msdn.microsoft.com/Forums/sharepoint/en-US/8c45b5e2-1fb8-435c-a97d-1d8c6d288d4c/caml-query-to-query-all-the-files-and-folders-in-document-library?forum=sharepointdevelopmentprevious
Kind regards
Stefan
http://www.n8d.at/blog
Follow me on Twitter: StFBauer |
n8design
Microsoft Community Contributor 2011 / 2012
MCTS - SharePoint / WSS Configuration and Development -
How to update file name of SharePoint form library?
HI All,
I have a Infopath form library and submitted as "Form-1". Once update and submit, the same form name should change as "Form-1.1" with out duplicating. How to achieve this, thanks in advance!Hi Sam, check out the following link. It will get you started. You'll have to customize the way the file is named differently than shown, but you'll get the idea:
http://claytoncobb.com/2009/06/20/auto-generating-filenames-for-infopath-forms/
cameron rautmann -
Assigning permission to SharePoint 2013 group using REST API
Hi All,
I was trying to assign permission to a group using REST but it failing with error message "Bad Request". Below is my REST code to assign Contribute permission to group with ID 95, It would great help if someone can help me to fix this.
// Set permission on a specific group
$.ajax({
url: "<Site URL>/_api/web/roleassignments/addroleassignment(principalid=95, roledefid=1073741827)",
type: "POST",
contentType: "application/json;odata=verbose",
headers: { "Accept": "application/json; odata=verbose","X-RequestDigest": $("#__REQUESTDIGEST").val(),"X-HTTP-Method": "POST" },
success: function (data) {
// Returning the results
alert('Contribute permission set on group');
alert("Error: " + JSON.stringify(data));
error: function (data) {
alert("Error: " + JSON.stringify(data));
~HarishHi Harish,
I have same problem and I just find solution for this error.
You must set body/data to null value --> It's work for me !!! :)
See my code with RequestExecutor (I develop an SharePoint App)
// Set the new role assignment for the group on the list.
this.setNewRoleForGroup = function (listTitle, newRoleDefId, groupId) {
var deferred = $.Deferred();
//First we must call the EnsureSetup method
JSRequest.EnsureSetup();
var hostweburl = decodeURIComponent(JSRequest.QueryString["SPHostUrl"]);
var appweburl = decodeURIComponent(JSRequest.QueryString["SPAppWebUrl"]);
//Tip to have a title formated to REST call
var arrayTitle = decodeURIComponent(listTitle).split("'");
var restQueryUrl = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/GetByTitle('" + arrayTitle.join("''") + "')/roleassignments/addroleassignment(principalid=" + groupId + ",roledefid=" + newRoleDefId + ")?@target='" + hostweburl + "'";
var executor = new SP.RequestExecutor(appweburl);
executor.executeAsync({
url: restQueryUrl,
body: null,
method: "POST",
headers: {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json; odata=verbose",
"X-HTTP-Method": "POST"
success: function (data, textStatus, xhr) {
deferred.resolve({ updated: true });
error: function (xhr, textStatus, errorThrown) {
deferred.reject(JSON.parse(xhr.body).error.message.value);
return deferred;
Maybe you are looking for
-
In the upper right hand corner of desktop I continually receive gray boxes with text asking me to accept/deny access to website access. "Do you want to allow connection to www.habbopromor7.blogspot.com". How do I get these removed permanently?
-
CAN YOU PLAY GAMES FROM YOUR IPHONE ON APPLE TV
can apple tv be used to play games from your iphone?
-
I wish to contribute to blogs which require me to sign in with Facebook or other services. I seem not to be able to do that and suspect my security settings are the cause. How can I open these services on a case by case basis. Examples in the UK ar
-
Providing UDID for 3.0 Activation
All, I just wanted to get some opinions on a matter. I was searching through ebay when I come across developers selling off their activations for iPhone 3.0 beta. I think this is a great idea and opportunity for the developers. It gives them the chan
-
New Folder on Desktop - Open It and It Shows Everything on Desktop
All of a sudden, if I create a new folder on my desktop, and click it, I do not get an empty folder, but rather I get my desktop and anything on it - like I'm looking at the desktop from the sidebar except its the folder content - which includes the