I am following the documentation from Microsoft found here:
to implement Cortana Integration into my Windows 10 app. However, I am getting the following error message...
"The system cannot find the file specified"
Here is my code for the OnLaunched method which is where I am trying to install the VCD...
protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootFrame;
}
if (e.PrelaunchActivated == false)
{
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
try
{
//StorageFile vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync("VoiceCommandDefinitions.xml");
//await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile);
var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///VoiceCommandDefinitions.xml"));
await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(storageFile);
}
catch (Exception)
{
throw;
}
}
I have got the VCD file in the root of my project and have set it to copy the file just as instructed by the documentation linked above.
Also, here is my VCD file named "VoiceCommandDefinitions.xml".
<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
<CommandSet xml:lang="en-gb" Name="VoiceCommands_en-gb">
<AppName>Hero Explorer</AppName>
<Example>Refresh the characters list</Example>
<Command Name="RefreshCharactersLIst">
<Example>Refresh the characters list</Example>
<ListenFor>Refresh [the] [characters] list</ListenFor>
<Feedback>Refreshing the characters list</Feedback>
<Navigate/>
</Command>
</CommandSet>
</VoiceCommands>
What am I doing wrong?
I have tested your code on my side and there is nothing wrong with your code. According to the error
The most possible reason is something wrong with your file location or file name. Firstly please ensure that the file name is same as code defined. After you created a new xml file for VCD file, the name you defined should be
VoiceCommandDefinitions
, notVoiceCommandDefinitions.xml
, the file already has suffix when you created it.Secondly, please ensure that your VCD file is actually location in the root of your project like the following picture shows.
At last, please also ensure that the
Build Action
property of the file is content in the project which will guarantee the file can be found when project running(right click the file -> properties).