0

I am trying to open multiple files at the same-time using file path.

Until now I was working on windows 10. So used below code

Process prc = Process.Start(“notepad.exe”, path);

Above opens multiple notepads which was fine in windows 10 for my requirement.

But after migrating to windows 11, I would like to open all those files in same window but different tabs like below.

Tabs in Notepad

Clemens
  • 123,504
  • 12
  • 155
  • 268
  • 1
    Did you enable tabs in Notepad? Because the screenshot is probably not yours but rather [copied without attribution](https://blogs.windows.com/windows-insider/2023/01/19/tabs-in-notepad-begins-rolling-out-to-windows-insiders/). IMHO the decision whether and how to use tabs should be left up to Notepad. If Notepad wanted to use tabs, it could do so. – Thomas Weller Mar 14 '23 at 12:52
  • Yes I tried opening the same files from explorer. It is opening in tabs. But when I call it in code it is opening separate notepad windows – Keshav Pratap K Mar 14 '23 at 13:18
  • 1
    How about `Process.Start("start", path)`? – Oliver Mar 14 '23 at 13:48
  • @Oliver: that certainly requires Notepad to be the default application for text files. – Thomas Weller Mar 14 '23 at 13:57

2 Answers2

0

I finally found a temporary working method for now using below code. Please comment if there is better way.

ProcessStartInfo pi = new ProcessStartInfo(file);
pi.Arguments = Path.GetFileName(file);
pi.UseShellExecute = true;
pi.WorkingDirectory = Path.GetDirectoryName(file);
pi.FileName = file;
pi.Verb = "OPEN";
Process.Start(pi);

Only drawback is notepad needs to be default application to open the file. Found above code in Open file with associated application

-5

try notepad++

Process myProcess = new Process(); 
Process.Start("notepad++.exe", "\"c:\\file name for test.txt\"");
Laxmikant
  • 588
  • 4
  • 11