Download attachments on display form

Hi,
How can I download attachments on display form?
Now MS Office file is opened by browser because we have a Office Online Server in Sharepoint farm.

Thank you in advance.

Dear @JugkritNWR,
So, the default behavior is to open Office documents in the browser, and you want to download them on the local PC, correct?

Dear @Nikita_Kurguzov ,
Yes, the default is to open office documents on Display form but I want to download attachments to local PC like Edit form.

Another question, are there some javascript to save all attached file on one go?

Dear @JugkritNWR,
For downloading attachments instead of opening, please, try the following code:

fd.spRendered(() => {
    const value = fd.field('Attachments').value;
    for (let i = 0; i < value.length; i++) {
        if (value[i].RedirectUrl) {
            value[i].RedirectUrl = value[i].RedirectUrl.replace('/Doc.aspx?sourcedoc=', '/download.aspx?SourceUrl=')
        }
    }
    
    fd.field('Attachments').$set(value, value);
})

As for downloading all attachments, we'll need to research this question. If you're interested in it, you can contact us at support@plumsail.com, we could offer paid support for such an option

@Nikita_Kurguzov ,
I have used your code on Display form but it is still the same, Office document is opened by browser. May be because of our Office Online server handle this action but for Edit Form, it allow us to download Office documents.

Dear @JugkritNWR,
Can you send us a screenshot of how the code looks in the editor? Also, are there any errors in browser's console when opening the form?

Dear @Nikita_Kurguzov ,
Below are the code editor screen shot of Display form, result of clicking an attached file and console log as attachment.

console.log (204.5 KB)

Dear @JugkritNWR,
Thank you! Can you check the attachment URLs in browser with Inspector tool? They should be updated to look like this:
{SharePoint site}/_layouts/15/download.aspx?SourceUrl={file url}

If this approach doesn't help, you can also configure how files should open - in a web app or in the desktop application via PowerShell:

Dear @Nikita_Kurguzov ,
The link is not updated as you mentioned, please see below picture.

I have followed as the above link before and it does not work for Sharepoint 2019.

Dear @Nikita_Kurguzov ,

I change the code as below and it work great.
const value = fd.field('Attachments').value;
for (let i = 0; i < value.length; i++) {
if (value[i].RedirectUrl) {
//value[i].RedirectUrl = value[i].RedirectUrl.replace('/Doc.aspx?sourcedoc=', '/download.aspx?SourceUrl=');
value[i].RedirectUrl = value[i].RedirectUrl.replace('/WopiFrame.aspx?sourcedoc=', '/download.aspx?SourceUrl=');
console.log(value[i].RedirectUrl);
}
}

Thank you very much for your support. :smile:

1 Like