Domanda

I faced with weird issue. I'm trying to add a new file to the library on button click event, everything is fine when site admin performs this action, but user with contributor permissions is getting access denied. Any thoughts how to fix this? I could not use elevating privileges because of missing "CreatedBy" field.

using (var site = new SPSite(SPContext.Current.Site.ID))
{
    using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
    {
        var list = web.Lists[%ListGUID%]
        var folder = list.RootFolder;

        SPFile file = folder.Files.Add(                
            "%Filename%.aspx",
            UTF8Encoding.UTF8.GetBytes(%PageMarkupAsString%));
    }
}

Test user 100% has "contributor" rights for test library.

È stato utile?

Soluzione

I found an answer here.

Users with contributor permissions are prevented from uploading files with the following extensions: ASPX; MASTER; XAP; SWF; JAR; ASMX; ASCX; XSN; XSF;

So my problem is in "aspx" extension of file I'm trying to create. This could be fixed by removing 'aspx' from WebApplication.WebFileExtensions collection.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top