[英]How to access the virtual directory path in c#?
I am working on worker service and created two virtual directories inside the IIS
server.我正在处理工作人员服务,并在IIS
服务器内创建了两个虚拟目录。 The goal is to move files from one folder to another.目标是将文件从一个文件夹移动到另一个文件夹。 The file moving part is working perfectly fine, It's just I need to provide the source and Destination directory path.文件移动部分工作得很好,只是我需要提供源和目标目录路径。
I put two folders in wwwroot
with the name Source
and Destination
.我在wwwroot
中放置了两个文件夹,名称为Source
和Destination
。 I looked upon blogs and google but couldn't find any extension.我查看了博客和谷歌,但找不到任何扩展。
Any hint would be appreciable.任何提示都会很明显。 Thanks谢谢
You can try to use the Microsoft.Web.Administration dll to get the virtual directory path.可以尝试使用Microsoft.Web.Administration dll获取虚拟目录路径。 you can use the following code as a reference.您可以使用以下代码作为参考。
ServerManager serverManager = new ServerManager();
// get the site (e.g. default)
Site site = serverManager.Sites.FirstOrDefault(s => s.Name == "Default Web Site");
// get the application that you are interested in
Application myApp = site.Applications["/Dev1"];
// get the physical path of the virtual directory
Console.WriteLine(myApp.VirtualDirectories[0].PhysicalPath);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.