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 embedded Resources.resx file of the project where my custom control will added to.
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 in stackoverflow, 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!!!


Answers
Know the answer? Post it. Somebody with the same question will find it here.