SetPermissions for file sharing on OneDrive / OneDrive For business? - onedrive

Can you advise??
I am trying to programmatically insert file permissions in OneDrive , OneDrive for business, SharePoint Online, not unlike how you can do it on Google Drive.
ie: https://developers.google.com/drive/v2/reference/permissions/insert
I cannot locate a OneDrive API scope/method to use to insert file permissions? (in effect to programmatically share a file). Does anyone happen to know if this is possible, and if so which scope/method to use? I assume its something such as SetPermission?
I am aware that you can get a link via the 'wl.skydrive' scope within OneDrive API although it is unclear as to whether there are any permissions added ?
Thank you in advance
James

The closest analog is shared edit and shared read links:
http://msdn.microsoft.com/en-us/library/dn631815.aspx#get_links_to_files_and_folders

If you are building a SharePoint app, you might want to try using the SPRoleAssignment class, which might also work for OneDrive for Business:
http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.sproleassignment(v=office.15).aspx
Basically, you create a group, add permissions level, and then assign that to an item.
You can also use the UpdateDocumentSharingInfo method (http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.sharing.documentsharingmanager.updatedocumentsharinginfo(v=office.15).aspx) from the DocumentSharingManager class to share internal files in OneDrive for Business.
Here’s how to make the call:
DocumentSharingManager.UpdateDocumentSharingInfo(
_ctx,
_resourceURL,
new List() { _newRoleAssignment },
validateExistingPermissions: true,
additiveMode: true,
sendServerManagedNotification: false,
customMessage: null,
includeAnonymousLinksInNotification: false);
_ctx.ExecuteQuery();

Related

Microsoft Graph: Uploading files to shared library instead of user's library?

In the documentation about Upload, these request options are listed:
PUT /me/drive/items/{parent-id}:/{filename}:/content
PUT /me/drive/root:/{parent-path}/{filename}:/content
PUT /me/drive/items/{parent-id}/children/{filename}/content
PUT /groups/<id>/drive/items/<parent-id>/children/<filename>/content
In the documentation about Resumable Uploads, Create an upload session show these options:
POST /me/drive/root:/{path-to-item}:/createUploadSession
POST /me/drive/items/{parent-item-id}:/{filename}:/createUploadSession
What if I have to upload to other (not 'me') drive? For example, the default shared library (https://mycompany.sharepoint.com/Shared%20Documents), which for any other porpoise besides uploading, the documentation says can be accessed like this:
/drives/{drive-id}/items/{item-id}
So, my question is: Is it possible to upload to "/Shared Documents"? If so, which is the right syntax for the PUT (small file) or POST (upload session)?
Perhaps something similar to this? (I just made this up, and it doesn't work)
PUT /drives/{drive-id}/items/{parent-id}/{filename}:/content
or (in case of an upload session):
POST /drives/{drive-id}/items/{parent-item-id}:/{filename}:/createUploadSession
For example, in the Graph Explorer, the response for something like this:
/v1.0/drives/THEDRIVEID/items/THEFOLDERID:/whatever.jpg:/createUploadSession
was:
{
"error": {
"code": "invalidRequest",
"message": "A valid path must be provided.",
"innerError": {
"request-id": "THERETURNEDID",
"date": "THERETURNEDDATE"
}
}
}
EDIT: Because the company's root can also be accessed as /drive/root/, I also tried (with no luck, in both 1.0 and beta):
/drive/root:/whatever.jpg:/createUploadSession
/drive/root/whatever.jpg:/createUploadSession
This is possible, but you need the right app permissions to be able to read/create files outside of the user's OneDrive. Instead of requesting Files.ReadWrite, you would need to request Sites.ReadWrite.All and then use /v1.0/drive/root:/file.bin:/createUploadSession.
You can also use the SharePoint Sites API in Microsoft Graph to access team site document libraries (other than the root site). However, this API is still in the beta version and should not be used in production apps.

Get directory tree of a users dropbox

I have an app which integrates with dropbox, I want the user to select a folder from their dropbox.
I can call '/2/files/list_folder' (https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder) with recursive set to true, and then recursively call it based on the returned cursor. I then filter out any which aren't directories.
But this is a long slow process, and unpredictable given the potential size of some users directory tree on Dropbox.
I know there is a dropbox file select plug in (https://www.dropbox.com/developers/chooser), but I want to make a folder select, with no option to select a file.
What I would like is one api call that returns a list of all directories for a user.
Does this exist with an API method I don't know about? Or is there another widget that allows folder selection?
I've seen this question which just does a recursive api call too, not practically efficient.
The Dropbox API v2 doesn't offer a way to list only folders like that, but we'll consider it a feature request.
Dropbox also doesn't offer a component like the Chooser that allows folder selection, but we'll consider that a feature request as well.

View all shared folders a member has access to

I've been looking at the Dropbox and Dropbox for Business API and I was trying to see if it would be possible to create a list of all the members and what shared folders they have access to.
I have found a project by Dropbox (Github Source) that lists all the shared folders and which people have access to them. I essentially want to do the opposite, list the users and what folders they have.
I have read through all the API (Core and Business) docs but can't seem to find a way to do it, unless I'm missing something. I also read about a preview of the new API, but again I don't think that is what I want.
Does anyone know if this can be done?
If I understand correctly what you're trying to do, you just need to call /shared_folders for each member of the team.
(You can list the members of the team via /team/members/list.)

Get lasting permission to write to a specific directory with the new Sandbox requirements

I need a way to get & keep permission to write to a specific directory in OS X. How can that be done while abiding with the new Sandbox requirements?
The recipe:
Ask the user to select the directory - use a standard open dialog limited to directory selection. Apart from a few special directories (music, pictures etc.) there is no way to gain access apart from asking the user.
Create a security-scoped bookmark using the URL returned by the standard open dialog, just search the Apple docs for "security-scoped bookmark".
Persist that bookmark, either in user preferences or in the Application Support folder for your app.
On application launch, or before you need access, read in the saved bookmark and activate - you'll find out how to do this in the Apple docs as above.

How can I get the Document Libraries permissions in Sharepoint 2010?

I'm developing a Webpart and I need to go through every document library and get its permissions. Basically I need to get the groups and its permissions associated with the document library.
I have iterated through the properties and methods of a SPDocumentLibrary object but couldn't find anything really.
Any help or guide would be appreciated.
Thank you
I would first check HasUniqueRoleAssignments. If it is false, then the permissions for that document library are inherited from the website. If it is true, as Jason said, I would then check the Member and RoleDefinitionBindings of each SPRoleAssignment.
Try SPDocomentLibrary.RoleAssignments.
This will give you SPRoleAssignments where the Member property is a SPGroup or a SPUser.