Search code examples
azureazure-storagefile-sharing

Is it possible to use System.File.IO with Azure File Share?


We can find everywhere how to use an azure file share with the rest api, but I have a legacy .net app that uses System.File.IO for accessing a file share. How can I access the file share using System.File.IO ? These azure file share were created for supporting legacy app but I don't see the point if I have to rewrite all my file access code.


Solution

  • I got the following solution, I run this at app start :

    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new
    System.Diagnostics.ProcessStartInfo
                {
                    FileName = "cmd.exe",
                    Arguments =
                            string.Format("net use * {0}  /u:{1}", ConfigurationManager.ApplicationSettings("StaticServerRoot"), ConfigurationManager.ApplicationSettings("StaticServerRootCredentials"))
                };
    process.StartInfo = startInfo;
    process.Start();
    process.Kill();
    

    Where StaticServerRootCredentials looks like this "AZURE\{account} {key}"

    I could use cmdkey