The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Requirement:
I need to display a downloadable PDF URL link in a Power BI report. The URL should contain an encrypted ID.
Problem Statement:
Query:
Would appreciate any guidance on the best way to implement this. Thanks in advance!
Solved! Go to Solution.
Hello @powerbidev123,
Since Power BI cannot run C# code natively, the best approach is to:
1. Host the C# encryption logic in an Azure Function, API, or Power Automate connector.
2. Call this API from Power BI to dynamically generate the encrypted URL.
a) So basically, a Power Automate Flow will take the unencrypted ID from Power BI.
using System;
using System.Web.Http;
using System.Security.Cryptography;
using System.Text;
public static class EncryptIDFunction
{
[FunctionName("EncryptID")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
string id = req.Query["id"];
if (string.IsNullOrEmpty(id)) return new BadRequestObjectResult("Missing ID");
string encryptedId = EncryptID(id);
string url = $"https://yourdomain.com/download?file={encryptedId}";
return new OkObjectResult(new { pdfUrl = url });
}
private static string EncryptID(string id)
{
using (var aes = Aes.Create())
{
aes.Key = Encoding.UTF8.GetBytes("your-32-byte-key");
aes.IV = Encoding.UTF8.GetBytes("your-16-byte-iv");
var encryptor = aes.CreateEncryptor();
byte[] encryptedBytes = encryptor.TransformFinalBlock(
Encoding.UTF8.GetBytes(id), 0, id.Length);
return Convert.ToBase64String(encryptedBytes);
}
}
}
b) Then, the Flow calls an Azure Function or C# Web API to encrypt the ID.
c)Finally, the encrypted URL is returned to Power BI and displayed in a table.
Hi @Sahir_Maharaj , let me check this. Will get back to you if this solution works
Hello @powerbidev123,
Since Power BI cannot run C# code natively, the best approach is to:
1. Host the C# encryption logic in an Azure Function, API, or Power Automate connector.
2. Call this API from Power BI to dynamically generate the encrypted URL.
a) So basically, a Power Automate Flow will take the unencrypted ID from Power BI.
using System;
using System.Web.Http;
using System.Security.Cryptography;
using System.Text;
public static class EncryptIDFunction
{
[FunctionName("EncryptID")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
string id = req.Query["id"];
if (string.IsNullOrEmpty(id)) return new BadRequestObjectResult("Missing ID");
string encryptedId = EncryptID(id);
string url = $"https://yourdomain.com/download?file={encryptedId}";
return new OkObjectResult(new { pdfUrl = url });
}
private static string EncryptID(string id)
{
using (var aes = Aes.Create())
{
aes.Key = Encoding.UTF8.GetBytes("your-32-byte-key");
aes.IV = Encoding.UTF8.GetBytes("your-16-byte-iv");
var encryptor = aes.CreateEncryptor();
byte[] encryptedBytes = encryptor.TransformFinalBlock(
Encoding.UTF8.GetBytes(id), 0, id.Length);
return Convert.ToBase64String(encryptedBytes);
}
}
}
b) Then, the Flow calls an Azure Function or C# Web API to encrypt the ID.
c)Finally, the encrypted URL is returned to Power BI and displayed in a table.
Hi @Sahir_Maharaj , let me check this. Will get back to you if this solution works