Forum Discussion
How can I test block download policies in SPO?
I have a Microsoft 365 E5 developer tenant. However, I am unable to activate the SharePoint Advanced Management trial from the SharePoint Admin Center. I need to verify my code in this configuration.
Specifically - I need to check how `File.OpenBinaryStream()` behaves.
Please advise.
3 Replies
We may test SharePoint Online (SPO) block download policies using PowerShell with Set-SPOSite -BlockDownloadPolicy $true. This forces browser-only access, preventing downloads, sync, and app access which including CSOM calls like File.OpenBinaryStream(), which will fail under this policy. However, enabling this requires the SharePoint Advanced Management add-on, which is not available in E5 Developer tenants.
https://learn.microsoft.com/en-us/sharepoint/block-download-from-sites
You’re trying to verify how CSOM File.OpenBinaryStream() behaves when a SharePoint site has Block Download Policy enabled, but your developer tenant will not offer the SharePoint Advanced Management trial. This policy requires SharePoint Advanced Management prerequisites, so a developer subscription cannot reproduce the supported configuration if that entitlement is unavailable. Use a licensed test tenant, create an isolated site and file, then enable the policy with Set-SPOSite -Identity <site> -BlockDownloadPolicy $true. Run the same CSOM code as a normal delegated user who can read the file, both before and after the policy applies. File.OpenBinaryStream() requests file content, so capture the resulting ClientRequestException or ServerException, status details, and correlation ID rather than assuming a particular error. Do not test with app-only authentication: Microsoft documents that app-only service applications are exempt. Without the required entitlement, there is no supported way to emulate this policy in that tenant
- CoralieSimonaireBrass Contributor
Hi,
The Block Download Policy requires SharePoint Advanced Management licensing to be enforced. If you cannot activate SharePoint Advanced Management in your developer tenant, you may not be able to reproduce the exact behavior.
I recommend validating the behavior of your application when the Block Download Policy is enabled.
I could not find any Microsoft documentation describing the specific behavior of File.OpenBinaryStream() when a Block Download Policy is applied.
Therefore, the most reliable approach would be to test against a tenant where SharePoint Advanced Management is available and the Block Download Policy can be enabled.
Hope this helps