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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
scroll top