4

How do I save a .mxd programatically? The project is never saved and on button-click, I want to save the project.

I use SaveFileDialog to get the filepath and then use the following:

IMapDocument mapDocument= ArcMap.Document as IMapDocument;
mapDocument.SaveAs(projectPath);

This crashes my ArcMap. Any suggestions?

  • Any error message or log file? – artwork21 Oct 1 '14 at 12:06
  • Can you confirm what the variable projectpath is? – Hornbydd Oct 1 '14 at 15:51
4

I was able to achieve results as following:

public void SaveProject()
{
    UID uid = new UIDClass();
    //uid.Value = "{119591DB-0255-11D2-8D20-080009EE4E51}"; 
    uid.Value = "esriArcMapUI.MxFileMenuItem";
    uid.SubType = 3;
    ICommandItem item = ArcMap.Application.Document.CommandBars.Find(uid, false);
    item.Execute();      
}

Appreciate your help.

3

you sure obtain IApplication/IMxApplication hook somehow in your code then you can obtain IMxDocument pointer and then cast it to IMapDocument:

IMxDocument ipMxDoc=(IMxApplication)ipApp;

//Suppose ipApp has been obtained via hook passed in OnCreate method of ICommand interface

IMapDocument ipMapDoc=(IMapDocument)ipMxDoc;

ipMapDoc.SaveAs(fileName);
//Suppose fileName obtained from a SaveDialogBox

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.