Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

c# - Open file - additional hidden information

When I want to open a file with its default application I simply use:

ProcessStartInfo startInfo = new ProcessStartInfo() {
    FileName = filePath,
    WorkingDirectory = new FileInfo(filePath).DirectoryName
};

Process.Start(startInfo);

But there is a problem: When I play an MP4 file from a directory within the windows explorer, the file is opened using Microsoft Movies & TV. But also the app gets information about other files in the same directory because there is the possibility to go to the next video. This only works when I am in the given directory inside the windows explorer when opening. When I use for example quick access to open the file I cannot go to other files although there are other videos inside the directory.

I created a blank console app to print all the parameters and then I opened an MP4 file with it:

static void Main(string[] args) {
    Console.WriteLine(args.Length);
    Console.WriteLine();

    foreach (string s in args)
        Console.WriteLine(s);

    Console.ReadKey();
}

But no matter where I open this app from (within the directory, quick access), it always outputs:

1

D:VideosVideo1.mp4

So the same parameters lead to different app behavior.

So where does this additional information come from and how to add it using Process.Start? Is there something registered within the registry which parameters should be passed to a given app? If so, how to get this information?

Edit: UWP FileActivatedEventArgs test try

protected override void OnFileActivated(FileActivatedEventArgs args) {
    var files = args.NeighboringFilesQuery.GetFilesAsync(0, args.NeighboringFilesQuery.GetItemCountAsync().GetResults()).GetResults();
    StringBuilder sb = new StringBuilder();

    foreach (var file in files) {
        sb.AppendLine(file.Name);
    }

    File.WriteAllText(@"D:Videosfiles.txt", sb.ToString());

    base.OnFileActivated(args);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...