我有一个Blazor组件libary,它有一个PDFGenerator组件。我通过Blazor服务器应用程序使用这个库,我必须发送图像路径以将其添加到PDF中。在开发阶段,它工作得很好,但是在部署到测试服务器之后,由于路径的原因,我得到了一个错误。
服务器应用程序:
var Path="..\\BlazorUI\\Blazor.Components\\wwwroot\\Images\\Logo.png"
Blazor组分libaray
Image image = section.Headers.Primary.AddImage(ImageSource.FromFile(path));
误差
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Webservice\BlazorUI\Blazor.Components\wwwroot\Images\Logo.png
服务器中图像文件夹的路径:
C:\Webservice\application\wwwroot\_content\Blazor.Components\Images
我的问题:
如何使用动态路径在开发阶段和测试服务器中工作?
谢谢
发布于 2022-01-20 08:57:22
我做了一个临时的解决方案:
var path = "";
var publishFolder = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\_content\\Blazor.Components");
//Publish mode
if (Directory.Exists(publishFolder))
{
path = Path.Combine(publishFolder, restPath);
}
//development mode
else
{
path = Path.Combine("..\\BlazorUI\\Blazor.Components\\wwwroot\\", restPath);
}
Image image = section.Footers.Primary.AddImage(ImageSource.FromFile(path));Note
发布后:此路径_content/Blazor.Components/Images已在服务器中主应用程序文件夹的wwwroot中创建。
https://stackoverflow.com/questions/70772334
复制相似问题