4

I have a provider hosted app. I am using app only permissions to upload and edit files in a document library.

I have a requirement to update the 'Created by' & 'Modified by' values once file is edited or added.

This works only if your app has 'Full Control' permission.

It does not work if your app has 'Manage' or 'Write' permissions. Interestingly, it does not throw exception and code just goes through without error.

Any help would be appreciated!

Here is the code snippet:

public void UpdateUserFields(ClientContext clientContext, Microsoft.SharePoint.Client.File file)
        {
            //* create user filed value string
            string _Author = "101;#i:0#.f|membership|[email protected]";

            //* get latest values
            clientContext.Load(file.ListItemAllFields);
            clientContext.ExecuteQuery();

            //* update field values
            file.ListItemAllFields["Author"] = _Author;
            file.ListItemAllFields["Editor"] = _Author;

            //* commit your changes
            clientContext.ExecuteQuery();
        }
2
  • 1
    I would argue that being able to do this would constitute a security hole. Feb 2, 2015 at 18:52
  • What is the question? Apr 7, 2015 at 1:34

2 Answers 2

1

SharePoint will automatically add the created by and modified by when an item is added and update the modified by when an item is changed. No code is required to achieve that, whether you use client side or server side code. If you are REQUIRED to do that for some reason, create new columns and display them and then hide the out of the box ones. Manually updating the out of the box columns content via code would be part of a security & troubleshooting nightmare.

0

You can run an App that has "App only permissions" in a user mode also.

This will apply the merged permissions of the App and the user (Permissions must be present in both, User and app)

If you do that the App can make modifications to files "In behalf of the user" and the modified/created fields will reflect that by adding the above text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.