【问题标题】:Get path to Silverlight ClientBin directory获取 Silverlight ClientBin 目录的路径
【发布时间】:2012-03-30 11:43:12
【问题描述】:

我正在尝试从 Silverlight 应用程序中的 .Web 项目中获取 ClientBin 目录的路径。目前,我的方法看起来像这样,但必须有更好/更简洁的方法来获取这条路径:

public static string GetClientBinPath()
{
   var applicationPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

   if (applicationPath.StartsWith(@"file:\"))
      applicationPath = applicationPath.Remove(0, 6);

   applicationPath = Path.Combine(applicationPath, @"..\ClientBin");

   return applicationPath;
}

【问题讨论】:

    标签: c# asp.net silverlight silverlight-4.0


    【解决方案1】:

    在 Web 项目中,您应该使用 HostingEnvironment 类的静态方法 MapPath

    string pathToClientBin = HostingEnvironment.MapPath("~/ClientBin");
    

    该类位于程序集 System.Web 的 System.Web.Hosting 命名空间中

    【讨论】:

    • 不错!谢谢你的快速反应。我知道必须有一种更简单的方法将虚拟空间“映射”到物理空间。
    【解决方案2】:

    我知道它已经过时了,但你去吧:

    currentDir = Path.GetDirectoryName(Application.Current.Host.Source.LocalPath);
    

    它适用于浏览器应用程序之外。我没有在浏览器中测试过。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-09
      • 1970-01-01
      • 2010-09-27
      • 2023-03-02
      • 2017-03-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多