0

我正在使用 EPi 服务器提供商:

<add virtualPath="~/WorkplaceFiles/" physicalPath="C:\Temp Files\Workplaces"
                  name="workplaceFiles" type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer"
                  showInFileManager="true" virtualName="workplaceUploadDocuments"  bypassAccessCheck="true" maxVersions="5" />

以下是提供者的定义:

VirtualPathUnifiedProvider provider =
    VirtualPathHandler.GetProvider(DocumentConstants.WorkplaceFiles) as VirtualPathUnifiedProvider;

我的问题来了——如果我定义一个字符串,例如:

string path = "2999/Documents/document.txt"
path = String.Concat(provider.VirtualPathRoot, path);

FileInfo file = new FileInfo(path);

FileInfo将无法找到此文件,因为它使用的是虚拟路径而不是物理路径。

如何获取物理路径,以便我能够找到带有 的文件FileInfo

// When I'm on  this line I would like my path string to be "C:\Temp Files\Workplaces\2999\Documents\document.txt"
FileInfo file = new FileInfo(path);
4

2 回答 2

1

再次阅读问题,正确的方法似乎是VirtualPathUnifiedProvider.TryGetHandledAbsolutePath

有了它,你会做这样的事情:

string path;
provider.TryGetHandledAbsolutePath("2999/Documents/document.txt", out path);

FileInfo file = new FileInfo(path);
于 2012-08-10T11:42:54.670 回答
1

这是您可以做的(如果您只知道 VPP 提供者的名称):

const string path = "Testbilder/startsidan_896x240.jpg";
var provider = VirtualPathHandler.GetProvider("SiteGlobalFiles") as VirtualPathUnifiedProvider;
if (provider != null)
{
    var virtualPath = VirtualPathUtilityEx.Combine(provider.VirtualPathRoot, path);
    var file = VirtualPathHandler.Instance.GetFile(virtualPath, true) as UnifiedFile;
    if (file != null)
    {
        var fileInfo = new FileInfo(file.LocalPath);
    }
}

如果您已经知道文件的完整虚拟路径,则可以直接转到 VirtualPathHandler.Instance.GetFile(...)。

您需要的命名空间是 EPiServer.Web 和 EPiServer.Web.Hosting(和 System.IO)。

于 2013-02-14T22:16:17.120 回答