Cannot upload .aspx file to Sharepoint Site Pages using Microsoft Graph

totally_gizmo 86 Reputation points
2023-01-05T18:08:51.633+00:00

Related Question (not answered): https://social.msdn.microsoft.com/Forums/en-US/b45a6cee-cc09-4820-9667-0af97f3030c4/cannot-upload-aspx-file?forum=sharepointdevelopment

Currently unable to upload .aspx files to the Site Page using Microsoft Graph. It doesn't matter if the file is empty or if it is a file with the content. Site Pages is a specific drive within the Site directory. Which mirrors the response above. If the file is named, .asp or any other ending for that matter, the file is able to be uploaded. This leads me to believe this is not a matter of permissions within the Azure portal.

Similar problems are experienced when trying to update template files within _catalogs/theme within Graph. Created a new question to address questions about restricted directories with Microsoft Graph. Any feedback on this issue would be greatly appreciated.

Microsoft Graph Site Lists API
Microsoft Graph Site Lists API
A Microsoft API that "supports access to SharePoint sites, lists, and drives; read-only support for site resources; read-write support for lists, listItems, and driveItems; and address resources by SharePoint ID, URL, or relative path.
264 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
6,068 questions
Microsoft Graph Applications API
Microsoft Graph Applications API
A Microsoft API that enables you to manage these resources and actions related to applications in Azure Active Directory.
432 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
1,696 questions
No comments
{count} votes

Accepted answer
  1. Tong Zhang_MSFT 8,801 Reputation points
    2023-01-19T08:53:20.89+00:00

    Hi @totally_gizmo,

    I'm glad to hear that you solved the problem and thanks for your sharing. If you have any issue about SharePoint, you are welcome to raise a ticket in this forum.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others." and according to the scenario introduced here: Answering your own questions on Microsoft Q&A, I would make a brief summary of this thread:

    [Cannot upload .aspx file to Sharepoint Site Pages using Microsoft Graph]

    Issue Symptom:

    Related Question (not answered): https://social.msdn.microsoft.com/Forums/en-US/b45a6cee-cc09-4820-9667-0af97f3030c4/cannot-upload-aspx-file?forum=sharepointdevelopment

    Currently unable to upload .aspx files to the Site Page using Microsoft Graph. It doesn't matter if the file is empty or if it is a file with the content. Site Pages is a specific drive within the Site directory. Which mirrors the response above. If the file is named, .asp or any other ending for that matter, the file is able to be uploaded. This leads me to believe this is not a matter of permissions within the Azure portal.

    Similar problems are experienced when trying to update template files within _catalogs/theme within Graph.

    Solutions:

    Newly released within Microsoft Graph Beta API, there is the Site Page API that allows for the creation of a .aspx file.
    It is a 2 part process.

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    No comments

4 additional answers

Sort by: Most helpful
  1. totally_gizmo 86 Reputation points
    2023-01-09T15:17:19.433+00:00

    FYI: This Office 365 admin center > SharePoint admin center > settings > Custom Script > is no longer the path to get to custom scripts.

    The following site gives instruction to add -admin to your <tenant>.sharepoint.com url. this will redirect to the admin center. From there the settings are on the left. Which will present a page. At the bottom of the page, navigate to the Classic settings page which will allow for the enabling of custom scripts.

    The page says that it can take up to 24 hours for the settings to be enabled. I will update if this fixes the issue.

    No comments

  2. Tong Zhang_MSFT 8,801 Reputation points
    2023-01-06T02:51:45.62+00:00

    Hi @totally_gizmo ,

    According to my research and testing, I can successfully upload .aspx file to SharePoint using the following Graph API:

    PUT https://graph.microsoft.com/v1.0/sites/{site-id}/drive/root:/file.aspx:/content  
    

    To help you better, please try to do some troubleshooting:

    1. Try testing again using the Graph API above.
    2. If it still fails to upload, are there any error messages? Can you share more detailed screenshots and information with me so that I can test this issue better?
    3. What is the response result?
    4. Check if you can successfully upload .aspx file on the SharePoint online UI.
    5. Check if the Custom Script feature is enabled: Please go to Office 365 admin center > SharePoint admin center > settings > Custom Script > check Allow users to run custom script on personal sites and Allow users to run custom script on self-service created sites.
      276771-01.png

    Here is a similar issue for reference: Cant upload aspx to Sharepoint online / office 365

    My test result:
    276718-02.png

    276753-image.png

    Hope it can help you. Thanks for your understanding.

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  3. totally_gizmo 86 Reputation points
    2023-01-09T14:45:07.6+00:00

    I think there is a misunderstanding. The uploading of the .aspx file at is not a problem with the Graph API. Uploading of the .aspx file into Sites Pages does not work via default. The call from Postman and the error is listed below:

    call:

       https://graph.microsoft.com/v1.0/drives/<sitePages>/root:/danny.aspx:/content  
    

    Error

       {  
           "error": {  
               "code": "accessDenied",  
               "message": "Access denied",  
               "innerError": {  
                   "date": "2023-01-09T14:41:40",  
                   "request-id": "reportID",  
                   "client-request-id": "requestID"  
               }  
           }  
       }  
    

    I have had no luck with changing the permissions.

    No comments

  4. totally_gizmo 86 Reputation points
    2023-01-09T19:24:03.42+00:00

    Newly released within Microsoft Graph Beta API, there is the Site Page API that allows for the creation of a .aspx file.
    It is a 2 part process.