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

Categories

0 votes
2.6k 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...