Solved

Need to get current path of a dll class library

Posted on 2015-01-29
3
69 Views
Last Modified: 2015-03-03
Hello,
I can't get the currently path of a dll class library, which is loaded as an ActiveX in a ASP.NET web site.
I have tried several commands, but no success. For example, I tried to get current path in variable _path:

namespace WebScanControl {

    [ApplicationControl(Width=640,Height=480)]
    public sealed partial class ScanControl:ApplicationControl {

        public ScanControl() {
            InitializeComponent();
        }

        protected override void Construct(ReadOnlyCollection<object> args) {
            try {

                string _path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);


            } catch(Exception ex) {
                MessageBox.Show(string.Format("{1}{0}{2}", Environment.NewLine, ex.Message, ex.StackTrace), ex.GetType().Name, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            base.Construct(args);
        }

     }
}

Open in new window

However, variable _path gets:

C:\Users\miyahira\AppDataLocalTemp\3f3574554-2ef8-e8r9-9c8b-e40561d03bb

Which is not its path.

As you see, this class library is an ApplicationControl. Is that tht reason why it's not possible to get its current path?
0
Comment
Question by:miyahira
3 Comments
 
LVL 33

Accepted Solution

by:
it_saige earned 300 total points
ID: 40578589
It's because you are using GetExecutingAssembly, which returns the executing assembly.  If you want to get the location of the DLL for the ApplicationControl type, you want to use the GetAssembly method, i.e. -
using System;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

namespace EE_Q28606618
{
	class Program
	{
		static TextBox textBox1 = new TextBox();
		static Color color1 = Color.AliceBlue;
		static SomeObject someObject1 = new SomeObject();

		static void Main(string[] args)
		{
			Console.WriteLine("Location of TextBox: {0}", Assembly.GetAssembly(textBox1.GetType()).Location);
			Console.WriteLine("Location of Color: {0}", Assembly.GetAssembly(color1.GetType()).Location);
			Console.WriteLine("Location of SomeObject: {0}", Assembly.GetAssembly(someObject1.GetType()).Location);
			Console.ReadLine();
		}
	}

	class SomeObject
	{
		public SomeObject() { ;}

		public override string ToString() { return "I am some object"; }
	}
}

Open in new window

Which produces the following output -Capture.JPG-saige-
0
 
LVL 1

Author Comment

by:miyahira
ID: 40578926
Sorry, I didn't explain myself clearly. What I am looking is the path where my created dll is loaded, I'm talking about  WebScanControl.dll.
0
 
LVL 35

Assisted Solution

by:Miguel Oz
Miguel Oz earned 200 total points
ID: 40580856
Please use CodeBase property as follows:
string _path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question