2013-01-18 8 views
5

Sto provando a utilizzare il metodo Launcher.LaunchFileAsync() con un file .txt di esempio e non funziona - restituisce sempre false per WordPad (che è il programma predefinito su Windows 8 per la visualizzazione di file .txt)."Windows.System.Launcher" non avvia WordPad

Tuttavia, se cambio le impostazioni di gestione .txt nel Pannello di controllo in Blocco note o Word tutto funziona correttamente, LaunchFileAsync() restituisce true e il file viene visualizzato correttamente.

Qualche idea, perché è così?

+0

Stai solo chiamando 'Launcher.LaunchFileAsync (" MyFile.txt "')', giusto? E sei sicuro che WordPad sia il gestore TXT predefinito? –

+0

Questo è un gestore di Click che sto chiamando: var picker = new FileOpenPicker(); picker.FileTypeFilter.Add (". Txt"); var file = attendi picker.PickSingleFileAsync(); var successo = attende Launcher.LaunchFileAsync (file); if (! Successo) { txtBlock1.Text = "Il file non può essere aperto."; } WordPad è il gestore predefinito per .txt su Windows 8 ma non dovrebbe avere importanza perché Launcher dovrebbe avviare qualsiasi app registrata come predefinita per un determinato tipo di file. –

+0

Posso confermare che mi è successo lo stesso. Purtroppo non ho una spiegazione o una soluzione per te. –

risposta

0

Se si desidera semplicemente eseguire un'applicazione desktop come (blocco note, wordpad, Internet Explorer, ecc.), Passare attraverso Process Methods e ProcessStartInfo Class.

try 
{ 
// Start the child process. 
    Process p = new Process(); 
    // Redirect the output stream of the child process. 
    p.StartInfo.UseShellExecute = false; 
    p.StartInfo.FileName = "C:\Path\To\App.exe"; 
    p.Start(); 
} 

// Uses the ProcessStartInfo class to start new processes, 
// both in a minimized mode. 

void OpenWithStartInfo() 
{ 
    ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); 
    startInfo.WindowStyle = ProcessWindowStyle.Minimized; 

    Process.Start(startInfo); 

    startInfo.Arguments = "www.northwindtraders.com"; 

    Process.Start(startInfo); 
}