C# Check SharePoint List permissions using SharePoint Client Object Model - c#

From a client application, I need to check if a given user has permissions on a given document library using Client object Model.
I want something equivalent of the following Server object function
spList.DoesUserHavePermissions(SPBasePermissions.EditListItems);
spList.DoesUserHavePermissions(SPBasePermissions.ManageLists);
spList.DoesUserHavePermissions(SPBasePermissions.AddListItems);
spList.DoesUserHavePermissions(SPBasePermissions.AddListItems)
Thank you !

I found a solution mentioned in this Blog for listItems permissions, and it worked fine for list.
the solution is as follow:
private static bool DoesUserHasPermission(ClientContext context, List list, PermissionKind permissionKind)
{
context.Load(list, t => t.EffectiveBasePermissions);
context.ExecuteQuery();
return list.EffectiveBasePermissions.Has(permissionKind);
}

From a client application the best approach would be use SharePoint web service. Sharepoint contains a lot of services that are usable for remote development by third-party developers.
In your case, I recommend use SharePoint Permission web service (http:///_vti_bin/permissions.asmx).
You could query Sharepoint about items permissions. Here is a step-by-step tutorial : http://jamestsai.net/Blog/post/Understand-SharePoint-Permissions-Part-2-Check-SharePoint-usergroup-permissions-with-Permissions-web-service-and-JavaScript.aspx

Related

Create an Azure Web App Using C#

Hi I'm currently refreshing my knowledge in C# programming.
I wanted to translate the manual way of creating a Web App in Microsoft Azure (Classic) into the C# language.
(Manual way - New > Compute > Web App > Custom Create > ...etc.. )
Whenever I search through google about this topic all it gives me is to literally create a "WebApp" in Visual Studio. (File > New > ...etc...) However, what I am looking for is how to create an Azure Web App programatically via C# - how to interact with the Management UI of the Classic Azure Portal to create a web app.
Anyone familiar to do this? Thanks in advance for the help! :)
To create an azure website easily using C#, you can use "Windows Azure Management Libraries". This SDK is a wrapper arround "Azure Service Management" API.
Here is a introduction from Braddy Gaster an a blog post, to get credentials from an Azure Tenant an work with ASM Api.
Then you will be able to create a website with something like this :
using (var AwsManagement = new Microsoft.WindowsAzure.Management.WebSites.WebSiteManagementClient(azureCredentials))
{
WebSiteCreateParameters parameters = new WebSiteCreateParameters()
{
Name = "myAws",
// this Service Plan must be created before
ServerFarm = "myServiceplan",
};
await AwsManagement.WebSites.CreateAsync("myWebSpace", parameters, CancellationToken.None);
}
I was able to work on the available code Microsoft posted in GitHub:
https://github.com/Azure/azure-sdk-for-net
I re-coded some and just acquired the functions that I only need for my program to work. :)
You can create a web site by using a POST request that includes the name of the web site and other information in the request body. You can check the code example for ASM here.

Sharepoint Provider Hosted User Permissions

I'm building a business app where read and write access permissions are important.
The project is a Provider hosted MVC 5 / SharePoint app built in Visual Studio 2012.
Johnny needs to be able to Read and Write content on SharePoint App A AND SharePoint App B
Dave needs to only be able to Read content on SharePoint App A
I've looked over a lot of documentation including this tutorial:
http://www.itunity.com/article/sharepoint-permissions-manage-access-sql-data-709
The problem is if I give Dave Read access at the site level he is allowed to access SharePoint App A but also SharePoint App B.
How do I effectively use SharePoint permissions to stop this unintended behaviour?
Should I even be using SharePoint permissions?
2nd example:
I am building an app for project management, there will be an Engineer who is able to create, read and edit projects, there is also an Accountant who views the projects billables.
If I give Read permissions to Engineer and Read permissions to Accountant, how do I know which can view the project details and which can view the project's billables?
I read the article you linked to, and I am not sure that this is "authorization", the right word is "authentication", in sharepoint you set what a user can do, authorization means- which data user can read or write
so a simple solution for you is creating Group in sharepoint, for any authorization type you have, for example, a group called "Engineer", and gives it the permissions you need, your engineers will be members in this group.
in your MVC attribute, accept the group as parameter and check if user is member in this group, show the user the relevant data according to its group
public SharePointPermissionsAuthorizationAttribute( params string group) { _groups = groups; }
[SharePointEffectivePermissionsFilter("Engineer"]
public ActionResult Index() { ... } }

Sharepoint webservice rename a folder

I am trying to use sharepoint webservice to rename a folder. I tried the below code to create a folder which works fine. But I am unable to find the webmethod related to renaming folder. Any help would be highly appreciated.
Web Service used
http://myservicelink:100/_vti_bin/Dws.asmx
Dws objDws = new Dws();
objDws.Credentials = System.Net.CredentialCache.DefaultCredentials;
string strResult = objDws.CreateFolder("MyMainFolders/MyFolder");
Console.WriteLine(strResult);
Console.ReadLine();
AFAIK there is no way to do it with web services API. But do you really have reasons to use the deprecated web-services API? (one I may think of is, you need to support SharePoint 2007 and below).
The better SharePoint API is called Share Point Client Object Model (CSOM). Here is a blog article explaining basic folder operations:
Manage (Create/Delete/Rename) list folders with SP Client Object Model

Unable to get the room list from online exchange using EWS Managed API?

My client has created rooms on online exchange. I can see list of rooms at outlook.office365.com
I am following this url (http://msdn.microsoft.com/EN-US/library/office/dn643730(v=exchg.150).aspx) to get the room list from exchange online, but empty list is being returned.
What am i doing wrong? Can anybody help me out?
Unfortunately the GetRooms and GetRoomLists methods, which at a glance appear to be exactly what you are looking for, actually require that one or more "Room Lists" be created on the Exchange server, with one or more existing rooms added to the relevant "Room Lists". Only once this is done will the methods you refer to actually produce any results.
Unfortunately all my research into this topic has (so far) found that the ONLY way anyone can create a room list is via a PowerShell command on the exchange server. It can't be configured through Office 365 settings or through any hosted exchange provider's interface (such as hosted exchange made available via Parallels systems).
If you do have powershell access, try something like this:
http://technet.microsoft.com/en-us/library/ee633471%28v=exchg.141%29.aspx
They way I did was to name all conference rooms with the prefix Conf. For example, ConfAAA1, ConfBBB2, ConfCCC3, etc. Then to retrieve a list of all rooms:
List<NameResolution> result = ExchangeService.ResolveName("Conf",
ResolveNameSearchLocation.ContactsThenDirectory, true).ToList<NameResolution>();

Modifying SharePoint List Using ASMX WebServices

I am writing a custom piece of code that dynamically creates modified document libraries. I've attempted to create a document library template, which succeeds in the UI but cannot be found via-webservices.
So to get to the point - I am attempting to:
1. Set "Allow Management Of Content Types" on the list.
2. Add a new Content Type (Already Created) to the list.
3. Set the new content type as the default content type.
4. Remove the "Document" content type from the list.
So far I have succeeded in being able to "Apply" the custom content type but the others are evading my grasp. The methods I have attempted are through the Lists.asmx service and the method described here: http://msdn.microsoft.com/en-us/library/websvclists.lists.updatelist.aspx
I tried setting the Flags property and a few other potential candidates with no success and no error messages complaining about what I was trying to attempt.
One limitation is that I do NOT have access to the sharepoint dll where this is living.
Once completed - this would be a plugin living in another non-sharepoint system. The only option to include the SharePoint client dll's would be to perform an ILMerge.
EDIT:
http://msdn.microsoft.com/en-us/library/sharepoint/jj193051.aspx (SharePoint 2013 Web Services)
http://msdn.microsoft.com/en-us/library/ee705814(v=office.16).aspx (SharePoint 2010 Web Services)
and yes - technically the ASMX services sound like they're on their way out: http://msdn.microsoft.com/en-us/library/sharepoint/jj164060.aspx
Edit: Tags are relevant to the question.
use SharePoint Client Object Model. This is a library that wraps calls to webservices that allows among other things to batch commands.
The operations you mention are all available.
here is a link to an article that explains Client Object Model:
http://www.codeproject.com/Articles/399156/SharePoint-2010-Client-Object-Model-Introduction
The article focus on ListItems but you can also interact with list properties, even web properties if you want.
Please note that you don't need to run Client Object Model from your sharepoint server. Note the "Client" part in the name.

Categories

Resources