简体   繁体   English

以Azure云服务工作者角色读取目录文件

[英]Read directory file in azure cloud service worker role

I am trying to read few sql files from directory in azure worker role. 我正在尝试从azure worker角色的目录中读取一些sql文件。 Here is my code, 这是我的代码,

string appRoot = Environment.GetEnvironmentVariable("RoleRoot");

string pathToFiles = Path.Combine(appRoot + @"\", @"approot\SQLScript\");

if (Directory.Exists(pathToFiles))
{
}

I have placed few sql files under SQLScript directory with copy always option, so that it copies those file in bin directory. 我已使用总是复制选项在SQLScript目录下放置了几个sql文件,以便它将这些文件复制到bin目录中。

Code works fine when I debug in local machine. 在本地计算机上调试时,代码工作正常。 But it's not working on azure. 但是它不能在天蓝色上工作。

This condition fails on azure, 这种情况在天青下失败,

if (Directory.Exists(pathToFiles)) { }

Had similar issue 发生过类似的问题

%ROLEROOT%\\approot\\MyDirectory can be accessible by scripts that ran on startup of the Role 角色启动时运行的脚本可以访问%ROLEROOT%\\ approot \\ MyDirectory

however if you RDP onto the VM that runs the Role you will not be able to access this path 但是,如果您将RDP连接到运行角色的VM,则将无法访问此路径

you can try referencing the files through relative path depends on what you wish to do with them 您可以尝试通过相对路径引用文件,具体取决于您希望对它们进行处理

hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM