में फ़ाइलों को कैसे लॉन्च करूं -एडिट- मुझे बेवकूफ लगता है। मुझे कुछ ऐसा लगता था जैसे नीचे दिए गए उत्तर काम करेंगे लेकिन नीचे दिए गए उत्तरों के समान कोई भी Google परिणाम नहीं देखा। तो जब मैंने इस जटिल कोड को देखा तो मैंने सोचा कि इसे इस तरह से होना चाहिए था।मैं सी #
मैंने यह Windows: List and Launch applications associated with an extension खोजा और पाया, हालांकि उसने मेरे प्रश्न का उत्तर नहीं दिया। नीचे tweaks के साथ मैं नीचे के साथ आया था। हालांकि यह छवि फ़ाइलों पर अटक गया है। TXT फ़ाइलें ठीक चलती हैं
मैं जल्द ही इस कोड को रिक्त स्थान के साथ ऐप पथ के लिए अपडेट कर दूंगा हालांकि मुझे नहीं पता कि छवि फ़ाइलों को क्यों लॉन्च नहीं किया जाता है।
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();
}
}
}
क्या आप सिर्फ विंडोज़ में फाइल लॉन्च करना चाहते हैं? –
उन छवि फ़ाइलों के साथ क्या होता है यदि आप लिखने की कोशिश कर रहे हैं जो परिणामी डीबग कथन उनके लिए कमांड लाइन पर है? –