I came across those two links:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_run_a_geoprocessing_tool/0001000003rr000000/
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Walkthrough_Consuming_a_geoprocessing_model_tool_in_NET/0001000001sw000000/
So you may be able to use this information to run a custum geoprocessing tool. That tool can execute the arcpy code give back the currently loaded document.
Using an texteditor create the following python script, say "getfile.py":
#importing the arcpy module into python
import arcpy
#setting the current document
mxd = arcpy.mapping.MapDocument("CURRENT")
#retrieving the filename and adding this to an message
arcpy.AddMessage(mxd.filePath)
Create a custum toolbox, say "MyTools".
- Import that script into your MyTools toolbox.
Try to run that geoprocessing tool and catch the message to get the filename.
Based upon the samples that code may look a bit like that, but I can not try it myself. You will have to play around with that by yourself.
using System;
using ESRI.ArcGIS.EsriSystem;
using ESRI.ArcGIS.Geoprocessing;
public void getfilenameTool()
{
object sev = null;
// Initialize the geoprocessor.
IGeoProcessor2 gp = new GeoProcessorClass();
// Add your toolbox, you will have to alter the path.
gp.AddToolbox(@"C:\temp\MyTools.tbx");
// Execute the tool by name.
gp.Execute("getfile", null, null);
string messages = gp.GetMessages(ref sev);
}
If you can not get the workaround with the geoprocessing tool to work you have two other workarounds.
A)
Because you can run that python script as a stand alone process from the command prompt you could call that script from C# and redirect the comand prompt output to your C# code.
In the python script replace the line
arcpy.AddMessage(mxd.filePath)
with
print mxd.filePath
B) Print the output of that python script into a file and read your filename from there.
In the python script replace the line
arcpy.AddMessage(mxd.filePath)
with
tempfile = open(r"C:\temp\tempfile.txt", "w")
tempfile.write(mxd.filePath)
tempfile.close()
You may then read that file with C# and get the filename of your ArcMap file from there.