2

I wrote a C# console application which connects to azure file share using net command and then perform some tasks on files. Below is the code which will connect to file share using process.It is working fine when running from local system as a console application.

string netUseCommand = applicationDbContext.AccountConfigurations.FirstOrDefault().NetUseCommand;//Get net use command from database
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo
{
   CreateNoWindow = false,
   UseShellExecute = false,
   Verb = "runas",
   FileName = "cmd.exe",
   WindowStyle = ProcessWindowStyle.Hidden,
   Arguments = @"/c " + netUseCommand + " & " + " Z: && " + "//command to perform file operations"
 };
try
{
  // Start the process with the info we specified.
  // Call WaitForExit and then the using statement will close.
  using (Process exeProcess = Process.Start(startInfo))
  {
     exeProcess.WaitForExit();  
  }
}
catch (Exception ex)
{
   // Log error.
   Console.Out.WriteLine("Error Occurred:  Error:" + ex.Message);
   throw ex;
}

When i deployed this console application as a webjob in azure it started failing while executing netuse command with the below error

[10/23/2018 04:12:45 > 7b7826: ERR ] Access is denied.

I found that azure Powershell is not supported in webjob. Is it the same issue with process(cmd.exe). Please provide the solution or any other alternatives solutions.

Thank you.

Nagasai
  • 131
  • 6
  • access is denied could be due to lack of authorization ,since you are accessing protected path like "c:/" may be you are not running the console file as admin .check this out https://stackoverflow.com/questions/2818179/how-do-i-force-my-net-application-to-run-as-administrator – TAHA SULTAN TEMURI Oct 23 '18 at 07:22

2 Answers2

1

You need to use the File Service REST API

For example, from the docs, in order to list files in a folder / directory, use:

https://myaccount.file.core.windows.net/myshare/mydirectorypath?restype=directory&comp=list

Then look for a C# library to perform the operations you need on the file, or write your own.

Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
1

As WebApp is a sandbox. It is not supported to use netuse command to map the drivers to operate the file share storage on the Azure WebApp.

If we want to operate the file storage on the Azure WebApp, as Murray Foxcroft mentioned that we could use the file service rest api. We also use Azure storage library to do that. We could get the C# demo code with azure storage library from azure official document.

If you still want to map the drives to operate the file storage, you could use Azure VM service to instead of Azure WebApp.

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47