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

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

Your code works fine in both my on-premises and SharePoint Online. I have given the app full control, so I suspect this is a permissions issue. I would check your permissions on your appmanifest. Must be something to do with publishing permissions. Try
giving full control and work the permissions down.
Blog | SharePoint Field Notes Dev Tools |
SPFastDeploy | SPRemoteAPIExplorer

Similar Messages

  • How to update managed metadata column for all file in document library using powershell

    Hi,
    How to update managed metadata column for all file in document library using powershell?
    Any help on it.
    Thanks & REgards
    Poomani Sankaran

    Hi TanPart,
    I have changed the code which you have give in order to get the files from SharePoint 2010 Foundation  Document Library.But i am getting below error in powershell.
    Property 'ListItemCollectionPosition' cannot be found on this object; make sure it exists and is settable.
    Could you tell me which is the issues in it?
    See the code below.
    $web = Get-SPWeb http://ntmoss2010:9090/Site
    $list = $web.Lists["DocLib"]
    $query = New-Object Microsoft.SharePoint.SPQuery
    $query.ViewAttributes = "Scope='Recursive'";
    $query.RowLimit = 2000
    $caml = '<Where><Contains><FieldRef Name="Title" /><Value Type="Text">Process Documents/Delivery</Value></Contains></Where>' +
            '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>'
    $query.Query = $caml
    do
        $listItems = $list.GetItems($query)
        $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
        foreach($item in $listItems)
            #Cast to SPListItem to avoid ambiguous overload error
            $spItem = [Microsoft.SharePoint.SPListItem]$item;
            Write-Host $spItem.Title       
    while ($spQuery.ListItemCollectionPosition -ne $null)
    Thanks & Regards
    Poomani Sankaran

  • Download older version of a file from SharePoint Document Library using CSOM and 404 error

    Hi,
    I am trying to download previous versions including Major and Minor versions of documents from SharePoint Online using CSOM. I get 404 error when I try to download the file. I found several posts on various discussion forums where people are getting same
    error but none of those have any solution/answer. Below is one of the threads and sample code I have tried that results in 404 error. If I use the link in browser directly, I am able to download the file. Also I am able to download the current version of file
    using CSOM without any problem, it is only the older versions that give me 404 in CSOM.
    http://qandasys.info/how-to-download-the-historical-file-version-content-using-csom/
    public int GetStreamFromFile(string docid, string lib, string fileurl, ClientContext clientContext, int iuserid, string Version, bool isCurrrent)
    if(!isCurrent)
    List LibraryName = clientContext.Web.Lists.GetByTitle(lib);
    clientContext.Load(LibraryName);
    clientContext.ExecuteQuery();
    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml = "" + fileurl +
    Microsoft.SharePoint.Client.ListItemCollection collListItem = LibraryName.GetItems(camlQuery);
    clientContext.Load(collListItem, items => items.Include(item => item.Id, item => item["FileLeafRef"], item => item["LinkFilename"],
    item => item["FileRef"], item => item["File_x0020_Size"], item => item["DocIcon"], item => item.File.Versions));
    //clientContext.Load(collListItem);
    clientContext.ExecuteQuery();
    foreach (Microsoft.SharePoint.Client.ListItem oListItem in collListItem)
    //string fileurl1 = (string)oListItem["FileRef"];
    //string filename = (string)oListItem["LinkFilename"];
    foreach (FileVersion version in oListItem.File.Versions)
    if (Version == version.VersionLabel)
    //Added excutequery to get object one more time as per blog
    //http://social.technet.microsoft.com/Forums/de-DE/sharepointdevelopmentprevious/thread/88a05256-8694-4e40-863d-6c77512e079b
    clientContext.ExecuteQuery();
    FileInformation fileInformation = ClientOM.File.OpenBinaryDirect(clientContext,version.Url);
    bytesarr = ReadFully(fileInformation.Stream);
    Darwaish

    Hi,
    According to your description,
    I know you want to get older version of a file from SharePoint Document Library using Client Object Model.
    The following code snippet for your reference:
    public void GetVersions()
    ClientContext clientContext = new ClientContext(“http://SPSite”);
    Web site = clientContext.Web;
    clientContext.Load(site);
    clientContext.ExecuteQuery();
    File file = site.GetFileByServerRelativeUrl(“/Shared Documents/mydocument.doc”);
    clientContext.Load(file);
    clientContext.ExecuteQuery();
    ListItem currentItem = file.ListItemAllFields;
    clientContext.Load(currentItem);
    clientContext.ExecuteQuery();
    FileVersionCollection versions = file.Versions;
    clientContext.Load(versions);
    clientContext.ExecuteQuery();
    if (versions != null)
    foreach(FileVersion _version in versions)
    Console.WriteLine(“Version : {0}”,_version.VersionLabel);
    More information:
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.file.versions.aspx
    Best Regards,
    Dennis Guo

  • How to add a file in Document Set using ECMA script?

    Hi,
    I want to upload a particular file into Document set using ECMA script.
    I can do it easily through C# but unable to achieve the same using ECMA Script.
    Any pointers or piece of code will be helpful.
    Thanx in advance :)
    "The Only Way To Get Smarter Is By Playing A Smarter Opponent"

    The following blog post provides a way to create a document set using ECMA:
    http://blogs.msdn.com/b/mittals/archive/2013/04/03/how-to-create-a-document-set-in-sharepoint-2013-using-javascript-client-side-object-model-jsom.aspx
    The following blog post provides a way to upload files into a document set using CSOM:
    http://www.c-sharpcorner.com/Blogs/12139/how-to-create-document-set-using-csom-in-sharepoint-2013.aspx
    See if you can follow the logic in the CSOM example to apply it to ECMA. Let me know if you have specific problems with it.
    Dimitri Ayrapetov (MCSE: SharePoint)

  • Unable to add XML files to genericObjects Folders using Webdav - cFolders

    Hi All
    I am not able to add XML files to genericObjects Folders using Webdav in cFolders
    What could be the reason.. When I try to copy, it says "cant read from source file"
    Regards,
    Aby

    Yes.. I downloaded the ECN.XML file from se80, edited and then used "Uplload and replace"..
    Also I did the same thing to add some more vocabulary in the cfx text XML, so that it would reflect correctly to map with Additional attributes in the PDX profile.
    Regards,
    Aby

  • Document Set Creation in document library using REST API in Sharepoint 2013

    Hi,
    I want to create the document set using REST API call. Currently i am able to create the folder and able to upload the files using REST API's in the document library. Is there any way we can pass the contentype name or Id and create the document set using
    REST API call. We need to create the document set along with metadata and upload the files inside the document set.
    I need to create the document set along with meta data column values using REST API. Please let me know how we can achieve this through REST API.
    Thank you,
    Mylsamy

    Hi,
    According to your post, my understanding is that you wanted to create document set along with managed metadata fields.
    The REST API does not currently support working with Managed Metadata or Taxonomy fields.
    As a workaround, we can use the JavaScript Client Object Model.
    Create document set using JavaScript Client Object Model.
    http://blogs.msdn.com/b/mittals/archive/2013/04/03/how-to-create-a-document-set-in-sharepoint-2013-using-javascript-client-side-object-model-jsom.aspx
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/aacd96dc-0fb2-4f0d-ab4c-f94ce819e3ed/create-document-sets-with-javascript-com-sharepoint-2010
    Set managed metadata field with JavaScript Client Object Model.
    http://sharepoint.stackexchange.com/questions/95933/add-list-item-with-managed-metadata-field-through-jsom
    http://sharepointfieldnotes.blogspot.com/2013/06/sharepoint-2013-code-tips-setting.html
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Jason Guo
    TechNet Community Support

  • Is it possible to get Exchange emails downloaded to SharePoint document library using Powershell and or Custom Workflow?

    I have been asked to see if it would be possible to get  exchange emails downloaded and or sent to a document library .
    I know of the sitemail box app. but we are not running Exchange 2013.
    and setting up the lists and or document library to receive emails using the built in doesn't seem to be working...( maybe not configured correctly, i would need to see what the prior admin/developer did)
    But is there a way to get the emails downloaded to a document library using a workflow and or a powershell script that is triggered via  workflow?

    Hi,
    Since workflow can only work on items in SharePoint sites, they cannot get Exchange emails, let alone download emails to SharePoint library. However, you could manually save email to local and upload it to SharePoint list/library.
    I'd suggest you toubleshooting the incoming email settings in SharePoint. Please refer to the article below and check your configuration:
    https://technet.microsoft.com/en-us/library/cc262947.aspx
    http://blogs.technet.com/b/harmeetw/archive/2012/12/29/sharepoint-2013-configure-incoming-emails-with-exchange-server-2013.aspx
    Regards,
    Rebecca Tu
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Unable to open html file in document library without saving first

    I've uploaded a bunch of HTML files from a DVD to a document library on our Sharepoint 2013 Enterprise server. When I try to open one of the html files it wants to save the file instead of opening it. If I choose to open the document library in Explorer
    I'm able to open the html files w/o issue.
    What's causing this? I know there is an option to set the file handing to permissive, but I'd rather not do that.

    Carl,
    See this link - http://sharepoint.stackexchange.com/questions/39020/how-do-i-prevent-sharepoint-from-asking-to-download-html-files-to-my-local-machi
    The allowed mime types are defined in theSPWebApplication.AllowedInlineDownloadedMimeTypes
    Property
    Here is small PowerShell utility function I use:
    function Add-SPAllowedInlineDownloadedMimeType{
    [CmdLetBinding()]
    param(
    [Parameter(Mandatory=$true, Position=0, ValueFromPipeLine=$true)]
    [Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind]$WebApplication,
    [Parameter(Mandatory=$true, Position=1)]
    [string]$MimeType
    process{
    $actualWebApp = $WebApplication.Read()
    if ($actualWebApp.AllowedInlineDownloadedMimeTypes -notcontains $mimetype)
    Write-Host "Adding MIME Type..."
    $actualWebApp.AllowedInlineDownloadedMimeTypes.Add($mimetype)
    $actualWebApp.Update()
    Write-Host "Done."
    } Else {
    Write-Host -ForegroundColor Green "MIME type is already added."
    And it can be used like this:
    Add-SPAllowedInlineDownloadedMimeType -WebApplication http://mywebapp -MimeType "text/html"
    Please 'propose as answer' if it helped you, also 'vote helpful' if you like this reply.

  • Unable to add certain files to iTunes Library or iPod

    For some reason, whenever I try to add some files with an .avi format to my iTunes Library or iPod just won't let me. I've tried the add file/folder option and it simply doesn't work. It does absolutely nothing. It won't let me drag/drop to the Library, only iPod. But when I try drag/dropping it to the iPod (as I've succesfully been able to do in the past with other files)I get an:
    "[File Name].avi" was not coppied to the iPod "[iPod Name]" because it cannot be played on this iPod.
    Thanks in advance for the help.

    sorry all. i restarted iTunes after i downloaded and installed QT and everything started working. total retardedness on my end

  • Allowing only pdf files in document library using Javascript

    HI,
    I have a document library in sharepoint 2013, where i want only pdf files to get uploaded in it. I have created event receiver for the same and it is working fine. but i want to restrict the files using javascript on
    the page itself, since, In event receiver, after the file is getting uploaded, it is checking and throwing error. So, is there any way to check for the file type before uploading the file and show error message if wrong file is uploaded?
    Harikrishna Baskaran

    Bind event to the upload button and add jquery to validate the file extension. Refer to the following posts for more information
    http://stackoverflow.com/questions/13124950/change-onclick-event-input-type-button-in-ie-8-9-ff-with-jquery-won%C2%B4t-wo
    http://stackoverflow.com/questions/4234589/validation-of-file-extension-before-uploading-file
    --Cheers

  • Schedule the Publishing date of a file in Document Library using CSOM

    I am having a hard time to schedule the publishing date of a document uploaded to a sharepoint document library. Basicaly, what I want is to upload a file to a document library and to schedule it´s publishing for a future date, using CSOM. Then someone should
    approve this (file content and scheduled date and time for publishing).
    I am able to upload the document to the document library and to start the approval workflow automatically (when the document is uploaded), but I don´t know how to set the publishing date using client side object model.
    Apparently all I need to do is to set up the properties ScheduledItem.StartDate and ScheduledItem.EndDate, but I just can´t manage to do it. Any help will be very much appreciated.

    I am having a hard time to schedule the publishing date of a document uploaded to a sharepoint document library. Basicaly, what I want is to upload a file to a document library and to schedule it´s publishing for a future date, using CSOM. Then someone should
    approve this (file content and scheduled date and time for publishing).
    Scheduling is enable and the coluns StartDate and EndDate are already added to the document library. I am able to upload the document to the document library and to start the approval workflow automatically (when the document is uploaded), but I don´t know
    how to set the publishing date using client side object model.
    Apparently all I need to do is to set up the properties ScheduledItem.StartDate and ScheduledItem.EndDate, but I just can´t manage to do it. Any help will be very much appreciated.

  • Unable to add aac file to itunes library.

    I have got songs in .aac format but i am unable to load it ot itunes library.Please suggest me how to load it to my ipod. I am using itunes7.

    Hi,
    Sorry my previous post doesnt specify neccesary informations.
    1. I have ipod shuffle (2GB capacity).
    2. I am using windows vista operating system on my laptop.
    3. I have installed itune7 which is latest.
    4. I have got abc.aac file on my local hard drive.
    5. I want to load this song in my ipod.
    6. I tried to drag drop the aac format songs on my itune library .... but it displays o drop sysmbol.
    7. Then i tried to add it to my library by File-> Add file to library option.It doesnt perform anything.. the song which i want doesnt appear in library or recently added option.
    please suggest.

  • Multiple File Upload With Metadata Using REST

    hi all
    I want to upload multiple files with metadata to document library using REST API. I am using this msdn article
    http://msdn.microsoft.com/en-us/library/office/dn769086(v=office.15).aspx for uploading file. I am able to upload single file to document library but it is not working for multiple file. when I select multiple file it is uploading last selected file. can
    anyone help with this. I am using office 365 environment.
    Thanks in advance

    Hi,
    According to your post, my understanding is that you wanted to use the REST to upload multiple files.
    Per my knowledge, the REST API is not supported for uploading multiple files via a single call.
    You can write your own loop to upload multiple files via an individual call.
    http://sharepoint.stackexchange.com/questions/108525/multiple-file-upload-with-metadata-using-rest/108532#108532
    More reference:
    http://sharepointfieldnotes.blogspot.com/2014/04/uploading-documents-and-setting.html
    http://www.shillier.com/archive/2013/03/26/uploading-files-in-sharepoint-2013-using-csom-and-rest.aspx
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • How to add a record in document library without upload file.

    Hi,
    how to add a record in document library without upload file?
    Is it possible? I want to create a folders in Document Library but inside folders i do not want to upload a file instead of just i want to create a record. I will map my local file path to the records.
    Can anyone help me on it?
    Thanks & Regards
    Poomani Sankaran

    Hello Sankaran,
    document library is to upload documents, without document you will not be able to add a record or Item to it.
    for your requirement you can use a list and enable folders within the list and maintain the local path of the file as an item in list.
    http://www.sharepointbriefing.com/spconfig/article.php/3834951/Enable-the-New-Folder-Creation-Option-in-SharePoint-Custom-Lists.htm
    My Blog- http://www.sharepoint-journey.com|
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful

  • Unable to edit .vsdx visio file that is inside a document library using visio 2010 sp2

    I have Visio 2010 SP2 installed locally inside my machine. The current version can open vsdx files by doing some conversions. I got the following scenario inside my SharePoint server 2013:-
    Currently I have Visio file (with .vsdx extension) uploaded to my SharePoint 2013 document library.
    If I click on the Visio file I got the following dialog.
    I select “Edit”, click on ok.
    Then the visio 2010 application will convert the current file and open it locally inside my machine.
    But the opened file will have it name as “Copy (1) of ….”, as follow:-
    So if I do some changes to the Visio file and I click on save I will not be able to save my changes back to the SharePoint server’s document library. Now if I do the same steps for a .vsd file not .vsdx then I can directly open the Visio file (without any
    conversion process) and I will be able to save my changes back to SharePoint server.
    So can anyone advice how to be able to edit .vsdx files which are uploaded to SharePoint document library using visio 2010 SP2 ?
    Thanks

    Thank you for your ideas.
    After that last posting, but before your response, I asked them to add the local farm to their trusted sites zone. Several blogs I had encountered while searching had listed that as something they had tried.
    As soon as they added the site to their trusted site zone, the problems went away.
    It was definitely not all users - I only had 2 people directly contact me about the issue.
    I never got a chance to ask them about other SharePoint sites - they were working on the sites where they spent most of their time - I don't know if they had other sites.
    The old location and the new location of these 2 sites are in the same site collection - it was moving them from
    http://myfarm/sites/div/dept67/site1
    to
    http://myfarm/sites/div/dept64/site1
    basically (with the actual names changed to protect my job).
    The site collection is /sites/div . So the site collection features are the same.
    I suppose that the site features could have changed between the export and the import - but since things are working now and I didn't change any features, I don't think that it is.
    At this point, things appear to be working. However strange that seems to me.

Maybe you are looking for