Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to get current path of a dll class library

Posted on 2015-01-29
3
Medium Priority
?
75 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 35

Accepted Solution

by:
it_saige earned 1200 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 36

Assisted Solution

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

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

886 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