Click here to Skip to main content
15,867,983 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on a custom control and I am trying to find a way to get the path of the project where my custom control will added to... Not the one where I am making it.

The reason is because I want to add some strings from my custom control into the embedded Resources.resx file of the project where my custom control will added to.

What I have tried:

Here is an example of my code...
C#
public class SVGEditor : UITypeEditor
{
    private OpenFileDialog open_file_dialog = null;

    protected virtual void InitializeDialog(OpenFileDialog open_file_dialog)
    {
        open_file_dialog.Title = "Select an SVG File: ";
        open_file_dialog.Filter = "SVG File (*.svg)|*.svg";
    }

    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
        if (provider is null || provider.GetService(typeof(IWindowsFormsEditorService)) is null)
        {
            return value;
        }

        Control ctrl = (Control)context.Instance;

        if (open_file_dialog is null)
        {
            open_file_dialog = new OpenFileDialog();
            InitializeDialog(open_file_dialog);
        }

        if (value is string s) open_file_dialog.FileName = s;

        if (open_file_dialog.ShowDialog() == DialogResult.OK)
        {
            ctrl.Select();
            ctrl.Capture = true;

            //[ The path of .resx file. ]
/* ---> */  string resx_file_path = Environment.CurrentDirectory + "\\Properties\\Resources.resx";

            //[ Generates resource's name by filename. ]
            string resource_name = Path.GetFileName(open_file_dialog.FileName);

            //[ Converts file's XmlDocument to string. ]
            XmlDocument xml_document = new XmlDocument { XmlResolver = null };
            xml_document.Load(open_file_dialog.FileName);
            string svg_image_document = xml_document.InnerXml;

            //[ Adds resource to .resx file. ]
            Helpers.ResourcesOperator.Add_or_Update_Resource(resource_name, svg_image_document, resx_file_path);

            //[ Returns only the name of resource. ]
            return resource_name;
        }

        return value;
    }
}
My "problem" located at the place where the /* ---> */ sign is.

I tried using Environment.CurrentDirectory and some other stuff I found, but with no luck. When I place my control to another project I get a message that could not find this path.

Thank you in advance!!!
Posted
Updated 11-Nov-22 3:54am
Comments
Member 15627495 11-Nov-22 9:48am    
do you try : application.resource..... ?
Simos Sigma 11-Nov-22 9:54am    
What do you mean?
Member 15627495 11-Nov-22 9:58am    
instead of "environment.currentdirectory",
the Application namespace permit to access resources.
so application.resource is a good way to reach 'resource'

I'm not convinced that you can edit/Add items in this part of the app, but you're on rail to.
Simos Sigma 11-Nov-22 10:05am    
I have managed to add/edit items programmatically. This already works. But not when I add my custom control into another project...

Can I have an example of "application.resource" way so to understand exactly what you mean?
Member 15627495 11-Nov-22 10:09am    
'environment' is part of the .Net dom. like 'Application' is.

type 'application' in your IDE, select the keyword, and press f1 to reach the microsoft help online.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900