Select to view content in your preferred language

Retrieve selected template path OnProjectOpened

358
4
04-03-2024 05:42 PM
Curtis
by
New Contributor

Hey all,

I'm currently capturing  the project open event to process some data, it's currently possible to determine if the project has been created from a template through the ProjectOpenMode enum, what I am trying to do is retrieve the path of template that was used but can't seem to find any events or data within the Project.Items that would point to the template path.

What I've tried:

var items = obj.Project.Items;

Checking all project items for the template name or path

var temp = Project.GetRecentProjectTemplates();

Getting the recent project templates, but this is only updated after its been used, I could work-around this by capturing it from the save event instead but it wouldn't be my first choice as it'd be a little messy

I've also tried something along the lines of:

var rtc = new RecentTemplatesControl();
rtc.SelectedTemplateChanged += OnSelectedTemplateChanged;

but naturally this didn't work because its not the actual reference to the control UI


Is there something I'm overlooking here?

 

Thanks,

Curtis

0 Kudos
4 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Start listening to OnProjectOpened event. You will find project path in ProjectEventArgs parameter.

private void OnProjectOpened(ProjectEventArgs obj) //Project Opened event handler
{
  MessageBox.Show($"{obj.Project.Path} has opened"); //show project path
}

 

0 Kudos
Curtis
by
New Contributor

Hi GKmieliauskas,

I'm actually looking for the template path that was loaded APTX, not the project path APRX.

My work around for this involves tracking the project load event and the project save event

looks like the following

private void OnProjectSaved(ProjectEventArgs obj)
{
_lastLoadedProject.ArcGisTemplate.FilePath = Project.GetRecentProjectTemplates()[^1];

but I was hoping for a better way to handle this

 

0 Kudos
GKmieliauskas
Esri Regular Contributor

You can call GetRecentProjectTemplates() and from ProjectEventArgs parameter directly:

private void OnProjectOpened(ProjectEventArgs obj) //Project Opened event handler
{
    _lastLoadedProject.ArcGisTemplate.FilePath = obj.Project.GetRecentProjectTemplates()[^1];
}
0 Kudos
Curtis
by
New Contributor

Unfortunately the RecentProjectTemplates gets updated after the project has been opened, which is why I'm capturing it in the save event.

Curtis_0-1712271613849.png

Curtis_2-1712272225711.png

 

Thanks for your time appreciate the response, seems as though I'll just have to capture it on the save event unfortunately.

0 Kudos