Programmatically open multiple files in Visual Studio (edit)
- Input: Danh sách đường dẫn của các tệp (array of physical file path)
- Output: Mở các tệp này trên Visual Studio
Open file in Visual Studio
https://stackoverflow.com/questions/21785363/programmatically-open-file-in-visual-studio/
Programmatically Search & Filter => Physical Path of Files => Open Files in Visual Studio
class Program
{
static string folder = System.Environment.CurrentDirectory;
static void Main(string[] args)
{
//ProcessSearch();
ProcessFilter();
Console.WriteLine("Press any key to exit..");
Console.ReadLine();
}
private static void ProcessFilter()
{
string s = @"
F:\Src\_Layout.cshtml
F:\Src\Home.cs
";
string[] arr = s.Split(new char[] { '\r', '\n' });
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
foreach (var str in arr)
{
if (str.EndsWith(".cs"))
{
string line = $"devenv /edit \"{str}\"";
sb1.AppendLine(line);
}
if (str.EndsWith(".cshtml"))
{
string line = $"devenv /edit \"{str}\"";
sb2.AppendLine(line);
}
}
string fileNew1 = System.IO.Path.Combine(folder, "Cs_Files.txt");
string fileNew2 = System.IO.Path.Combine(folder, "Cshtml_Files.txt");
System.IO.File.WriteAllText(fileNew1, sb1.ToString(), Encoding.UTF8);
System.IO.File.WriteAllText(fileNew2, sb2.ToString(), Encoding.UTF8);
}
static void ProcessSearch()
{
string file = System.IO.Path.Combine(folder, "TextFile1.txt");
string str = System.IO.File.ReadAllText(file, Encoding.UTF8);
string[] arr = str.Split(new[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
var hs = new HashSet<string>();
foreach (var s in arr)
{
var items = s.Trim().Split(new char[] { ' ', '\t', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var item in items)
{
if (item.Contains(".cs") || item.Contains(".cshtml") && System.IO.File.Exists(item))
{
hs.Add(item);
}
}
}
StringBuilder sb = new StringBuilder();
foreach (var s in hs)
{
string f = @"F:\Src" + s;
if (System.IO.File.Exists(f))
{
sb.AppendLine(f);
}
}
string fileNew = System.IO.Path.Combine(folder, "TextFile2.txt");
System.IO.File.WriteAllText(fileNew, sb.ToString(), Encoding.UTF8);
}
}
Programmatically Search Code in Visual Studio => Copy & Paste the Search Result into the "TextFile1.txt"
class Program
{
static void Main(string[] args)
{
string folder = System.Environment.CurrentDirectory;
string file = System.IO.Path.Combine(folder, "TextFile1.txt");
string str = System.IO.File.ReadAllText(file, Encoding.UTF8);
string[] arr = str.Split(new[] { System.Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
StringBuilder sb = new StringBuilder();
foreach (var item in arr)
{
if (item.Contains(".cs "))
sb.AppendLine(item);
}
string fileNew = System.IO.Path.Combine(folder, "TextFile2.txt");
System.IO.File.WriteAllText(fileNew, sb.ToString(), Encoding.UTF8);
}
}