John Russell
John Russell

Reputation: 2247

Get path to Silverlight ClientBin directory

I'm trying to get the path to the ClientBin directory from within my .Web project inside a Silverlight application. Currently, my method looks like this, but there has to be a better/more concise way to get this path:

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;
}

Upvotes: 2

Views: 5254

Answers (2)

user3749514
user3749514

Reputation: 1

I know it is old but here you go:

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

It works for out of the browser application. I haven't test it in the browser.

Upvotes: 0

Jehof
Jehof

Reputation: 35544

In the Web project you should use the static method MapPath of the HostingEnvironment class.

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

The class is located in the System.Web.Hosting namespace of the assembly System.Web

Upvotes: 3

Related Questions