【问题标题】:Is it possible to use System.File.IO with Azure File Share?是否可以将 System.File.IO 与 Azure 文件共享一起使用?
【发布时间】:2017-08-18 08:12:49
【问题描述】:

我们到处都可以找到如何将 azure 文件共享与其他 api 一起使用,但我有一个使用 System.File.IO 访问文件共享的旧版 .net 应用程序。如何使用 System.File.IO 访问文件共享?这些 azure 文件共享是为支持旧版应用程序而创建的,但如果我必须重写所有文件访问代码,我看不到这一点。

【问题讨论】:

    标签: azure azure-storage file-sharing


    【解决方案1】:

    我得到了以下解决方案,我在应用启动时运行它:

    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();
    

    StaticServerRootCredentials 看起来像这样“AZURE\{account} {key}”

    我可以使用 cmdkey

    【讨论】:

      【解决方案2】:

      如何使用 System.File.IO 访问文件共享?

      您可以使用 Azure 文件共享。完成 Azure 文件共享后,您可以使用 System.File.IO 通过同一 Windows 中的映射驱动器访问共享。

      Mount an Azure File share and access the share in Windows

      否则,您只能使用 REST API 或任何客户端 SDK 访问文件共享。如果您使用 .NET Framework,则可以下载并使用 Azure Storage .NET SDK。

      Develop for Azure File storage with .NET

      【讨论】:

      • 文件共享只挂载当前用户权限?
      • 那么如何为在 IIS 中运行的应用程序执行此操作?
      • 如果您确实需要使用 .NET File API,请采取以下线程中提到的方式。 stackoverflow.com/questions/35412669/… 我对其进行了测试,并且在我这边工作得很好。确保您仅通过 UNC 路径格式访问文件和文件夹,就像原始海报在线程中所做的那样。
      • 查看我的回答,但您的解决方案仅适用于 1 个帐户。我只有其中一个,但对其他人来说可能是个问题。感谢您的帮助。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      相关资源
      最近更新 更多