Open SharePoint list item attachment in view mode

Varghese, Ajith (Cognizant) 0 Reputation points
2024-08-07T12:48:54.1+00:00

Wanted to open list item attachments in View Mode in browser.

"<SiteURL>/Lists/<ListName>/Attachments/<ListID>/<filename>?web=1&action=View" is opening the document in edit mode only even though action=View is appended to the query.

Is there any parameter that helps in opening the attachments in View mode in browser?

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Ling Zhou_MSFT 23,620 Reputation points Microsoft External Staff
    2024-08-08T01:58:24.2866667+00:00

    Hi @Varghese, Ajith (Cognizant),

    Thank you for posting in this community.

    It seems, you would like to make the attachment in SharePoint list as Read-only mode.

    I understand that it would be more convenient if can open the attachment in Read-only mode. Unfortunately, there is no out of box feature to achieve the requirement at this moment.

    We are always looking for ways to improve SharePoint, and your feedback and suggestions are very valuable. We suggest that you can make suggestions on this SharePoint Feedback portal for opening SharePoint list item attachment in view mode. Your contribution will be highly appreciated.

    Meanwhile, after research a lot based on your requirement. Some users mentioned workaround by created a read-only document with custom workflow.

    For your reference: Setting attachments to Read Only after upload to an item on a custom list

    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. 

    In addition, I also found that creating a flow in Power Automate (Microsoft Flow) may be able to achieve this target. For your information: Set an item to read only in flow, attachment cannot be read anymore

    I appreciate your understanding and stay safe!!


    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.

    0 comments No comments

  2. Varghese, Ajith (Cognizant) 0 Reputation points
    2024-08-08T02:16:18.31+00:00

    Thank you for your response?

    How can we get the SP list item attachment GUID using code?

    Below URL will open the attachment in View mode. Wanted to know how we can get this DocGUID.

    SiteURL/_layouts/15/Doc.aspx?sourcedoc=DocGUID&file=FileName&action=View

    0 comments No comments

  3. Ling Zhou_MSFT 23,620 Reputation points Microsoft External Staff
    2024-08-09T05:30:46.37+00:00

    Hi @Varghese, Ajith (Cognizant),

    Thank you for posting in this community.

    Here’s a sample code snippet using JavaScript and the SharePoint REST API to get DocGUID:

    // Get the list item by ID
    var itemId = 1; // Replace with your item ID
    var listTitle = "YourListTitle"; // Replace with your list title
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/items(" + itemId + ")/attachmentFiles",
        type: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function(data) {
            var attachments = data.d.results;
            attachments.forEach(function(attachment) {
                console.log("Attachment Name: " + attachment.FileName);
                console.log("SourceDoc ID: " + attachment.UniqueId); // This is the sourcedoc ID
            });
        },
        error: function(error) {
            console.log("Error: " + JSON.stringify(error));
        }
    });
    

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.