Solved

Need to get current path of a dll class library

Posted on 2015-01-29
3
71 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 34

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 36

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom authorization on controller action and HTML in asp.net mvc 1 57
asp.net get gridview datakey from row command 2 45
Problem to copy file 14 92
asp.net repeater 2 38
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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