Solved

Need to get current path of a dll class library

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

863 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

26 Experts available now in Live!

Get 1:1 Help Now