如何在我的 asp .net / c# 项目代码中使用脚本文件夹的相对路径?
这个问题应该相对简单,甚至不需要太多解释,我认为不需要,这里是:
我的网站正在使用 Process 对象执行批处理文件,该对象需要 .bat 文件的路径当然
我将在多个服务器上托管我的网站因此我不想给出绝对路径,我只想在我的项目中使用相对路径(例如,在我制作项目时使用由 Visual Studio 自动生成的脚本文件夹)
我只是不确定如何在其中引用该文件代码一旦位于脚本文件夹中。
这是我当前引用我的 .bat 的代码:
p.StartInfo.WorkingDirectory = "C:\\Users\\e\\Desktop\\Test_Bat_Thing";
p.StartInfo.FileName = "C:\\Users\\e\\Desktop\\Test_Bat_Thing\\test.bat";
它工作得很好。但我希望它是类似于
p.StartInfo.WorkingDirectory = ".\\scripts";
p.StartInfo.FileName = ".\\scripts\\test.bat";
请帮忙!提前致谢 :)
this question should be relatively simple and shouldnt even require much explanation i dont think, here goes:
my website is executing a batch file using the Process object which requires a path to the .bat file of course
i will be housing my site on multiple servers therefore i dont want to give an absolute path i want to just use a relative path within my project (for example use the scripts folder automatically generated by visual studio when i made my project)
i just am not sure exactly how to reference that file within the code once its in the scripts folder.
here is my current code for referencing my .bat:
p.StartInfo.WorkingDirectory = "C:\\Users\\e\\Desktop\\Test_Bat_Thing";
p.StartInfo.FileName = "C:\\Users\\e\\Desktop\\Test_Bat_Thing\\test.bat";
which works perfectly. but i want it to be something along the lines of
p.StartInfo.WorkingDirectory = ".\\scripts";
p.StartInfo.FileName = ".\\scripts\\test.bat";
please help! thanks in advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用
"~/"
(Web Root Operator)作为站点 Web 根文件夹的引用。您还可以使用以下方法将虚拟路径转换为物理路径:
Web Root Operator:
有关详细信息,请参阅 MSDN:ASP.NET Web 项目路径
Try out using
"~/"
(Web Root Operator) as reference to the site web root folder.Also you can convert Virtual Path into a Physical Path using:
Web Root Operator:
For more details see on MSDN: ASP.NET Web Project Paths
尝试如下操作:
Try something like the following:
如果您需要引用当前用户的桌面路径,您可以使用此语句,
您的代码将如下所示
If you need to reference the Desktop Path of the current user, you can use this statement
your code will look like