[Mono-list] SPAM-LOW: Re: how to get relative path

Charlie Poole charlie at nunit.com
Mon Jan 12 19:25:33 EST 2009


Interesting... I didn't know about this project. Anyone involved
is free to take the code and use it if they like.

Charlie 

> -----Original Message-----
> From: mono-list-bounces at lists.ximian.com 
> [mailto:mono-list-bounces at lists.ximian.com] On Behalf Of 
> "Andrés G. Aragoneses"
> Sent: Monday, January 12, 2009 1:45 PM
> To: Mono-list at lists.ximian.com
> Subject: SPAM-LOW: Re: [Mono-list] how to get relative path
> 
> 
> This would be a good inclusion to Mono.Rocks.
> 
> 	Andrés
> 
> 
> Charlie Poole wrote:
> > Right, but beware that you have to do some post-processing on the 
> > Codebase return value to get it to work as a local path, 
> especially if 
> > you want it to work on both Linux and Windows. Here's what 
> I use, in 
> > case it's helpful to anyone:
> > 
> >         public static string GetAssemblyPath(Assembly assembly)
> >         {
> >             string path = assembly.CodeBase;
> >             Uri uri = new Uri(path);
> > 
> >             // If it wasn't loaded locally, use the Location
> >             if (!uri.IsFile)
> >                 return assembly.Location;
> > 
> >             if (uri.IsUnc)
> >                 return path.Substring(Uri.UriSchemeFile.Length + 1);
> > 
> > 
> >             int start = Uri.UriSchemeFile.Length + 
> > Uri.SchemeDelimiter.Length;
> > 
> >             if (path[start] == '/' && path[start + 2] == ':')
> >                 ++start;
> > 
> >             return path.Substring(start);
> >         }
> > 
> > Charlie
> > 
> >> -----Original Message-----
> >> From: Andrus [mailto:kobruleht2 at hot.ee]
> >> Sent: Monday, January 12, 2009 12:33 PM
> >> To: Charlie Poole; 'Chris Howie'; 'YyYo'
> >> Cc: mono-list at lists.ximian.com
> >> Subject: Re: [Mono-list] Re: how to get relative path
> >>
> >>> This will break if the program is loaded from the shadow 
> copy cache.
> >>
> >> You can use CodeBase instead which works with shadow 
> assemblies also:
> >>
> >> String strAppDir = Path.GetDirectoryName(
> >>                  
> Assembly.GetExecutingAssembly().GetName().CodeBase);
> >>
> >> Andrus.
> >>
> > 
> > 
> > 
> > _______________________________________________
> > Mono-list maillist  -  Mono-list at lists.ximian.com 
> > http://lists.ximian.com/mailman/listinfo/mono-list
> > 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com 
> http://lists.ximian.com/mailman/listinfo/mono-list
> 





More information about the Mono-list mailing list