Solved

Need to get current path of a dll class library

Posted on 2015-01-29
3
65 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 32

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now