none
C# i want c# code to open two .cs files in VS2010 RRS feed

  • Question

  • Hi Everyone,

    I want c# code to open two .cs files in VS2010.

    -->Initially VS 2010 close mode.

    -->Both .cs files belonging into same solution and project

    -->Both need to open in single VS 2010.

    Please help me

    Wednesday, February 6, 2013 9:04 AM

Answers

  • Let’s suppose that the solution is “MySolution.sln” and the files are “Program.cs” and “Class1.cs”. Then try this:

    Process p = new Process(); p.StartInfo.FileName = @"C:\Program Files\Visual Studio 2010\Common7\IDE\devenv.com";
    p.StartInfo.Arguments = @"C:\MyFolder\MySolution.sln /command ""of C:\MyFolder\Program.cs C:\MyFolder\Class1.cs"" "; p.Start();


    Adjust all of the paths before experimenting.



    Wednesday, February 6, 2013 10:24 AM
  • Because Visual Studio supports DDE commands and .cs files are generally associated to VS2010 by default in Windows Registry (with Shell - Open - ddeexec) , you can also try :

    var si = new System.Diagnostics.ProcessStartInfo {UseShellExecute = true, FileName = "c:\test\test1.cs", Verb = "Open"};
    System.Diagnostics.Process.Start(si);

    This method may have the following advantage : you can open one file, and later open another one without launching VS2010 again.

    A more complex method providing full VS automation:

    1) Add COM References to  "Microsoft Development Environement 8.0", "Microsoft Development Environement 9.0" and "Microsoft Development Environement 10.0" to your project

    2) Execute:

    var dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.10.0"); if (dte==null) { Type type = Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); dte = (EnvDTE80.DTE2)Activator.CreateInstance(type); dte.MainWindow.Visible = true; } dte.Documents.Open(@"C:\Users\Renaud\Documents\test1.cs");

    dte.Documents.Open(@"C:\Users\Renaud\Documents\test2.cs");

    Enjoy and discover the full VS power !


    Thursday, February 14, 2013 12:48 AM

All replies

  • Hi,

    go to File->Open->File . Then select your appropiate file to open.


    One good question is equivalent to ten best answers.

    Wednesday, February 6, 2013 9:18 AM
  • Let’s suppose that the solution is “MySolution.sln” and the files are “Program.cs” and “Class1.cs”. Then try this:

    Process p = new Process(); p.StartInfo.FileName = @"C:\Program Files\Visual Studio 2010\Common7\IDE\devenv.com";
    p.StartInfo.Arguments = @"C:\MyFolder\MySolution.sln /command ""of C:\MyFolder\Program.cs C:\MyFolder\Class1.cs"" "; p.Start();


    Adjust all of the paths before experimenting.



    Wednesday, February 6, 2013 10:24 AM
  • Because Visual Studio supports DDE commands and .cs files are generally associated to VS2010 by default in Windows Registry (with Shell - Open - ddeexec) , you can also try :

    var si = new System.Diagnostics.ProcessStartInfo {UseShellExecute = true, FileName = "c:\test\test1.cs", Verb = "Open"};
    System.Diagnostics.Process.Start(si);

    This method may have the following advantage : you can open one file, and later open another one without launching VS2010 again.

    A more complex method providing full VS automation:

    1) Add COM References to  "Microsoft Development Environement 8.0", "Microsoft Development Environement 9.0" and "Microsoft Development Environement 10.0" to your project

    2) Execute:

    var dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.10.0"); if (dte==null) { Type type = Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); dte = (EnvDTE80.DTE2)Activator.CreateInstance(type); dte.MainWindow.Visible = true; } dte.Documents.Open(@"C:\Users\Renaud\Documents\test1.cs");

    dte.Documents.Open(@"C:\Users\Renaud\Documents\test2.cs");

    Enjoy and discover the full VS power !


    Thursday, February 14, 2013 12:48 AM