Quantcast
Channel: Developing Apps for SharePoint 2013 forum
Viewing all articles
Browse latest Browse all 8089

Unable to add aspx file to document library using REST and JSOM in SharePoint Hosted App

$
0
0

Hi,

I am unable to add an aspx file to document library.  I was actually trying to create a WIKI page and upload to Pages library but that wasn't working so I tried simple document library.  It keeps failing with Access Denied error.  I have checked the blocked types and aspx is not included.  I can upload it directly from the browser so that shouldn't be the case.  I have read that it can be achieved with CSOM but I need this to work with a SharePoint Hosted App.  Here is my JSOM:

factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
    context.set_webRequestExecutorFactory(factory);
    appContextSite = new SP.AppContextSite(context, hostweburl);
    oWeb = appContextSite.get_web();
    oList = oWeb.get_lists().getByTitle('Documents');

    fileCreateInfo = new SP.FileCreationInformation();
    fileCreateInfo.set_url("mywiki.aspx");
    fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
    fileContent = "<%@ Page Inherits=\"Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" %> <%@ Reference VirtualPath=\"~TemplatePageUrl\" %> <%@ Reference VirtualPath=\"~masterurl/custom.master\" %>";

    for (var i = 0; i < fileContent.length; i++) {
        fileCreateInfo.get_content().append(fileContent.charCodeAt(i));
    }

    newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);

    context.load(newFile);
    context.executeQueryAsync(function () {
        alert('yo');
    }, function (sender, args) {
        alert(args.get_message() + '\n' + args.get_stackTrace());
    });

If I change the file extension to "txt", it works.  Same with REST implementation, it works with "txt" but fails with "aspx".  Maybe what I am trying to do will not work using JSOM or REST.  Any suggestions?  Your help is always appreciated.

Regards,


kashif


Viewing all articles
Browse latest Browse all 8089

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>