Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get location of DLL from C# code.

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
12373 Views, 6 Replies

Get location of DLL from C# code.

I need to retrieve the directory where the plugin DLL resides. When I use the usual C# code for this, Directory.GetCurrentDirectory(), I get the location of the RevIt installation on my machine, and not the directory where the running DLL is located. Is there a way, through the API, to retrieve the location of the running DLL?

 

Thanks in advance,

 

Scott S

Research Programmer

Center for Research Computing

University of Notre Dame

6 REPLIES 6
Message 2 of 7
Anonymous
in reply to: Anonymous

String executablePath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

 

should do the trick.

 

Message 3 of 7
Anonymous
in reply to: Anonymous

Absolutely, that did it! Thanks so much!

Message 4 of 7
jaboone
in reply to: Anonymous

I am using macro and getting an error on assembly not found.  Is there a solution for that?

 

The name 'Assembly' does not exist in the current context (CS0103) - C:\ProgramData\Autodesk\Revit\Macros\2015\Revit\AppHookup\CConvert\Source\CConvert\ThisApplication.cs:55,62

Learning as I go
Message 5 of 7
Dale.Bartlett
in reply to: jaboone

I'm guessing that macros (as opposed to addins) are code run within the document. As such there is no dll or assembly.



______________
Yes, I'm Satoshi.
Message 6 of 7
jaboone
in reply to: Dale.Bartlett

I am using application specific macro so I can use VS later.  This is only short term testing right now.  There are dll.

Learning as I go
Message 7 of 7
Dale.Bartlett
in reply to: jaboone

The solution accepted here does not work for 2017. It returns the location of the .addin file, not the location of the executing dll which is in a .bundle sub-folder. I have only just picked up that my support help files are not being found, although were previously. Has there been a change for 2017? I have also tried various suggestions with no success. In fact they return the same.

public static string GetDLLFolder()
        {
            string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
            UriBuilder uri = new UriBuilder(codeBase);
            string path = Uri.UnescapeDataString(uri.Path);
            return Path.GetDirectoryName(path);
        }

Thanks, Dale




______________
Yes, I'm Satoshi.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community