Files
microsoft--semantic-kernel/dotnet/samples/Concepts/Plugins/WebPlugins.cs
T
wehub-resource-sync b957a53def
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:21:23 +08:00

48 lines
1.4 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using Microsoft.SemanticKernel.Plugins.Web;
namespace Plugins;
/// <summary>
/// Sample showing how to use the Semantic Kernel web plugins correctly.
/// </summary>
public sealed class WebPlugins(ITestOutputHelper output) : BaseTest(output)
{
/// <summary>
/// Shows how to download to a temporary directory on the local machine.
/// </summary>
[Fact]
public async Task DownloadSKLogoAsync()
{
var uri = new Uri("https://raw.githubusercontent.com/microsoft/semantic-kernel/refs/heads/main/docs/images/sk_logo.png");
var folderPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
var filePath = Path.Combine(folderPath, "sk_logo.png");
try
{
Directory.CreateDirectory(folderPath);
var webFileDownload = new WebFileDownloadPlugin(this.LoggerFactory)
{
AllowedDomains = ["raw.githubusercontent.com"],
AllowedFolders = [folderPath]
};
await webFileDownload.DownloadToFileAsync(uri, filePath);
if (Path.Exists(filePath))
{
Output.WriteLine($"Successfully downloaded to {filePath}");
}
}
finally
{
if (Path.Exists(folderPath))
{
Directory.Delete(folderPath, true);
}
}
}
}