0

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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