Get user performing action in Sharepoint CSOM - sharepoint

We are using SharePoint client object model (CSOM) and REST/OData endpoints to retrieve/manage data on sharepoint.
Is there anyway to get information on the user performing the MOVE on a file (for example, move file from folder A to folder B within same site collection)? When I use this REST API call before and after the move, Author and Editor remains the same even though a completely different user moved the file from folder A to folder B. SPChangeItem does not seem to have any members with this information either.
https://{site_url}/_api/web/GetFileByServerRelativePath(DecodedUrl=#fileUrl)?$expand=Author,ListItemAllFields,ListItemAllFields/ParentList,ListItemAllFields/ParentList/ParentWeb&$select=UniqueId,Author/LoginName,Author/Email,Author/Id,Editor/LoginName,Editor/Email,Name,UserName,ServerRelativeUrl,MajorVersion,MinorVersion,Length,ListItemAllFields&#fileUrl={url_encoded_file_path}
Is there anyway to get logged in user while using REST API?
When I use this REST API call, Id returned is the user corresponding to Bearer accesstoken.
https://{site_url}/_api/Web/CurrentUser?$select=Id

When moving a file to another folder, the metadata including author/editor is remained the same one, what changed is only the location. This is by designed.
If we want to know the user who performed this operation, we could check the version events of the file as it will immediately prompt an modification event when moving a file.
FileVersionEvent
Rest API endpoint:
_api/Web/GetFileByServerRelativePath('filepath')/VersionEvents
Thanks

Related

Graph API: Get Sharepoint drive item by id if drive is unknown

I added a sharepoint file browser to my app using MS Graph API to enumerate document libraries/folder/files. When selecting a file I get a driveitem id, a drive id and a webUrl (and of course many other properties).
I would like to store a reference to the selected file in a safe way: If a file is moved to another library (on same site collection) or renamed, the reference should still be valid.
I guess for office type files, I could use the webUrl, because it is a durable link and does not change. For other file types, a file can be identified by combination of driveid and itemid and queried in graph api like
https://graph.microsoft.com/v1.0/sites/{my_site}/drives/{drive-id}/items/{item-id}
If I rename a file, the item id is not changed. That's great.
If I move a file to another library, the item id is also not changed, but the drive id changes. I didn't find a way to query for a drive id across all drives on a site collection. Is it possible? Or is my approch wrong?
If the document id feature was enabled on the site collection, I could probably use this id to identify a file. But I cannot guarantee that (and I also don't know how to search by document id in Graph API).
P.S. If there is a better way to access files by id in CSOM, I could also use this instead of Graph API...

Automatic response when file is added to folder (Dropbox API)

So once the User has been authenticated and given an access token,
I want the user to be able to externally add a file into a Dropbox folder for example:
the user goes to dropbox.com, logs in and adds a new file called Dogs.png to a folder called Dogs
Then I want use the Dropbox API to somehow tell by backend that a file has been added to the folder Dogs, and then send some information about that file (e.g. filename) to the client.
This is a very conceptual post i'm quite new to these technologies, what's the best way to handle this problem, or am I thinking about it the right way?
If you want your app's server to be notified of changes in the accounts of users who have connected to your app, you should use the Dropbox webhooks feature. The documentation there covers how to register a URI for your server where Dropbox will send notifications for changes.
Note that those webhook notifications only tell when something has changed for a particular user, but not what has changed. To find out what changed, you can then call the Dropbox API, e.g., the /2/files/list_folder[/continue] endpoints.

Api to access Conversation History and In Place Hold for Office 365

We are trying to access the Conversation History in Office 365 for accessing the chat history.We are using the Rest Apis provided in https://msdn.microsoft.com/en-us/office/office365/api/API-catalog#Outlookmail . However , we are unable to get the folder id of the folder Conversation History . As a result , we are not able to fetch the mails under Conversation History. Is there a way to get access to the chat history under the folder "Conversation History ?
We are also , interested to get the data for chats which might be deleted by mistake by the users from Conversation History. Hence , we are looking for getting the data for in place hold users as well.
Please use https://outlook.office365.com/api/v1.0/me/folders/ConversationHistory/Messages to get the messages in ConversationHistory folder. For well known folder names (Inbox, DeletedItems, ConversationHistory etc.), we allow you to specify the folder ID or the well known name. The response always refers to the folder using the folder ID. We will look into why https://outlook.office365.com/api/v1.0/folders/ConversationHistory is failing.

xPages xAgent Security

I'm currently implementing the OpenNTF Multiple File Uploader by Mark Leusink.
This very nice custom control uses an xAgent to embed the selected file attachment into the target Notes document. Everything was working fine until I added Authors and Readers fields to the Notes documents. Now I'm getting a security error (402) when uploading the file.
My thought is the Upload xAgent can't edit the target document to attach the file. If I remove the security fields, everything works again.
My question is, do xAgents run with the same security as the current user? If not, can I set a "run as" user for the xAgent like I can for a Lotus Script agent?
I'd suggest that you look at the xAgent's code and rewrite it to use sessionAsSigner to access the database/document to upload the file. This will cause it to run as the signer of the application and bypass the security issues that your running into.
Both Tom's and Declan's answers are correct, but this doesn't count for the file uploader.
It uses a Flash component to do the actual uploading (called SWFUpload). Since browser cookies aren't shared with Flash, it can't send along the user's session cookie with the file and therefore to the Domino server the user performing the upload is nog logged in (aka Anonymous). That's why the uploader requires anonymous users to be allowed to read/write public documents in the ACL and the XPage/ XAgent handling the uploaded files (aUpload.xsp) is set to allow "public access users". It uses the sessionAsSigner object to access the database's content
Normally, the above settings would allow everyone to anonymously upload files. That's why I implemented a custom authentication solution based on an idea by Mark Barton: before every file is uploaded, a request is made to an XPage to retrieve a unique key. That XPage (aGetAuth.xsp) does run under the user's credentials and stores the key in a document in the database. This key is send along with the uploaded file and compared with the stored key. The upload is only allowed if the keys match.
First thing I'd check in your case if the code in the aUpload.xsp XAgent can read and write the target document using the sessionAsSigner call.
Mark, Declan, and Tim, thanks for jumping in.
I modified the xAgent **aGetAuth.xsp** to use sessionAsSigner to get the current database. At first I got the error "sessionAsSigner not found".
Google showed a quick answer was to re-sign the template before testing. After re-signing the template, twice, and preforming a "clean" everything works brilliantly.

Temporary Internet File (read from SharePoint via IE). How do I find the URL?

When an IE user clicks the link of a file residing in SharePoint (and user selects "read-only" access), the file is copied to Temporary Internet Files, my application is opened and passed that filename as a parameter. I'm trying to implement a "check out" button in my app so that a user can switch from read-only mode to check-out and edit mode. I haven't been able to find a way to learn the SharePoint URL for the file. On check-out and edit, it's no problem: there's a registry entry that maps the file on my system to the URL in SharePoint; I haven't found anything like that for read-only files.
EDIT:
There is a URL column available in Windows Explorer, but when I display that column (in Explorer), all the values are blank. Also, I can't find any file information api call that will return this value for me.
UPDATE:
I found some promising calls in the wininet.lib: FindFirstUrlCacheEntryEx (and "next") along with FindFirstUrlCacheGroup (and next). They didn't seem to return any data, and from what I read, these only return my application's use of the wininet api calls cache -- not I.E.'s.
I also tried running through the list of COM calls that IE made into my app when the file was opened to see what interfaces it was seeing if I supported. One that looked promising was the IMonikerProp interface, which, when I implemented it, did get called... however it only provided me with the mime type property, the classid of my app and the TrustedDownload flag.
Maybe this site has the answer: How SharePoint communicates with Word via ActiveX
Another option could be to hook into the SharePoint ItemCheckingOut event. Example 1 Example 2 . In the event you could get the URL info and create some temporary file with the info or pass the info off to your program.
Link to ActiveX control info - Maybe this control is launched on everything? You might be able to tap into that.
Does the temporary file created have a good name (does it match what the file is actually called or is it gibberish). If it's a good name, you can probably search for it. Otherwise, without knowing the site, folder, filename, you might not be able to unless there is some additional data about the file somewhere.

Resources