operativa -Editazione- mi sento come un idiota. Avevo la sensazione che la risposta qui sotto funzionasse, ma non ho visto risultati di Google simili alle risposte di seguito. Quindi quando ho visto questo codice complesso ho pensato che doveva essere così.Come faccio a lanciare i file in C#
Ho cercato e trovato questo Windows: List and Launch applications associated with an extension però non ha ancora risposto alla mia domanda. Con le modifiche qui sotto ho trovato il sotto. Tuttavia rimane bloccato sui file di immagine. file txt funzionano bene
aggiornerò questo codice presto per spiegare i percorsi app con gli spazi però non capisco il motivo per cui i file di immagine dont lancio.
static void launchFile(string fn)
{
//majority was taken from
//https://stackoverflow.com/questions/24954/windows-list-and-launch-applications-associated-with-an-extension
const string extPathTemplate = @"HKEY_CLASSES_ROOT\{0}";
const string cmdPathTemplate = @"HKEY_CLASSES_ROOT\{0}\shell\open\command";
string ext = Path.GetExtension(fn);
var extPath = string.Format(extPathTemplate, ext);
var docName = Registry.GetValue(extPath, string.Empty, string.Empty) as string;
if (!string.IsNullOrEmpty(docName))
{
// 2. Find out which command is associated with our extension
var associatedCmdPath = string.Format(cmdPathTemplate, docName);
var associatedCmd = Registry.GetValue(associatedCmdPath, string.Empty, string.Empty) as string;
if (!string.IsNullOrEmpty(associatedCmd))
{
//Console.WriteLine("\"{0}\" command is associated with {1} extension", associatedCmd, ext);
var p = new Process();
p.StartInfo.FileName = associatedCmd.Split(' ')[0];
string s2 = associatedCmd.Substring(p.StartInfo.FileName.Length + 1);
s2 = s2.Replace("%1", string.Format("\"{0}\"", fn));
p.StartInfo.Arguments = s2;//string.Format("\"{0}\"", fn);
p.Start();
}
}
}
Avete voglia di lanciare i file in Windows? –
Cosa succede con quei file di immagine se si tenta di scrivere qualunque sia l'istruzione di debug risultante per loro solo sulla riga di comando? –