Click here to Skip to main content
15,886,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to get the path of the assembly the code (.exe) in an add-in for outlook 2010 (in c#).

I use :

Assembly.GetExecutingAssembly().Location


but it returns the assembly (.dll)

I need to get it to write to an xml file.

Can you help me please.
Posted

1 solution

C#
static string getDirectoryPath()
      {
          string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
          string folderpath = System.IO.Path.GetDirectoryName(path);
          return folderpath;
      }
 
Share this answer
 
Comments
Member 10872485 4-Aug-14 7:46am    
Excuse me, but it doesn't work in my add-in c# for outlook, but I rephrase my question, how can I write to an xml file from my add-in c# for outlook.
So, in myFile.config, I have :
...
add key="Test1" value="My value 1" add
...
and in my add-in.cs :

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
m_Application = this.Application;
XmlDocument doc = new XmlDocument();
doc.Load(Assembly.GetExecutingAssembly().Location + ".config");

// To read from myFile.config
System.Window.Forms.MessageBox.Show(ConfigurationManager.AppSettings[key]);

// To write in myFile.config

// retrieve appSettings node
XmlNode node = doc.SelectSingleNode("//appSettings");

// Select the 'add' element that contains the key
XmlElement elem = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='{0}']", "Test1"));
if (elem != null)
{
// add value for key
elem.SetAttribute("value", "TestValue");
}

else
{
// Key was not found so create the 'add' element and set it's key/value attributes
elem = doc.CreateElement("add");
elem.SetAttribute("key", "Test1");
elem.SetAttribute("value", "TestValue");
node.AppendChild(elem);
}

doc.Save(Assembly.GetExecutingAssembly().Location + ".config");
}
I can't read or write in myFile.config and the reason goes back to the Assembly.GetExecutingAssembly().Location + ".config" !!!

Thank you in advance :)

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