Windows Develop Bookmark and Share   
 index > Windows Forms General > Current Project Path through a Class Library ?
 

Current Project Path through a Class Library ?

Hello,

I'mcurrently developping a customized control which extends "MenuStrip". This class isinside a Class Library.

I'd like to create a file related to the control when it is dropped on the form.

Example:

public class CustomizedMenu : MenuStrip

{

protected override void OnControlAdded(ControlEventArgs e)

{

base.OnControlAdded(e);

// Create file

...

try

{

// Get project path

..

// Open or Create file

FileStream fs = File.Open(path + "/xml/"+ this.Name, FileMode.OpenOrCreate);

...

// Close the stream

fs.Close();

}catch(Exception)

{

throw;

}

}

}

Ibuild the library DLL.

Then I create a new project and add this library. I drag and drop the customized control on the form and this should create the file.

But it doesn't, because the path to the project where the file should be createdis wrong.

I don't know how to get the current project path from the library.

At this moment I can only get the path of the library project, or the path of its assembly, but not the path of the current project in which the control's added.

How toretrieve it ?

I've tried Assembly.GetCallingAssembly(), Assembly.GetEntryAssembly(), etc.. no luck.

This is what I want:

1) Create a new project

2) Import the DLL as reference

3) Drag'n Drop the control on the form

4) It creates a file inside the current project

5) It refresh the current project Treeview (on the right by default)

I don't know how to do the step 5 either...

Please help me :-)

Thanks

NuCl3aR  Monday, March 31, 2008 9:13 AM

When the control is deployed there's no concept of a "current project folder", just the current folder. Your users willhave to make sure whatever files are needed by the control are copied as well.

Peter Ritchie  Monday, March 31, 2008 6:18 PM

Add a file path string property to it, so you can specify the path at run time from the parent object

G_Sharp  Monday, March 31, 2008 9:31 AM

Hello, thanks for the reply.

However, I want this control to make the developers life easier. Also I wanted to the control gets the path by itself, automatically.

But if there is no other way, I'll pick this one.

NuCl3aR  Monday, March 31, 2008 9:38 AM

When the control is deployed there's no concept of a "current project folder", just the current folder. Your users willhave to make sure whatever files are needed by the control are copied as well.

Peter Ritchie  Monday, March 31, 2008 6:18 PM

Hmm, I wonder how friendly will this kind ofcontrol to Safe Source and other source control programs. This on the fly file sometimes gives us trouble.

JRQ  Monday, March 31, 2008 8:37 PM

Thanks for the answer

I've given up this idea, because as JRQ said, it ain't really friendly to Source Safe..

But it's good to know that there is no "current project folder"

NuCl3aR  Tuesday, April 01, 2008 5:59 AM

You can use google to search for other answers

Custom Search

More Threads

• Accessing to ext2/3, xfs on Windows
• Dynamically add text boxes
• Filtering ListView
• Read line to line in an array from an textbox
• Please help how to change form control property from other class
• tabbing across multiple forms
• Change Focus after Move
• displaying custom control in datagridview column
• RaiseEvent Skipped ?
• Printing Windows Forms