Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7803953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:45:15+00:00 2026-06-02T01:45:15+00:00

I have a project that generates text (representing an interface and a class) based

  • 0

I have a project that generates text (representing an interface and a class) based on metadata. I would like to take this generated code and insert it as a new class and interface directly into the currently opened solution under a specific project and directory. I will create the menu tool that will generate the class but what I don’t know how to do is gain access to the following items from within my custom Visual Studio Extension:

  1. Iterate the current solution and find a project to dump the generated code into.
  2. Open a new file window within Visual Studio and inject the generated text that comes from my tool directly into that window.
  3. Create a new folder in a specific project within the current solution from within my custom extension.

EDIT –
To clarify I need to open a new file (e.g. Right Click on a Project -> Add – > New Class) and insert text into it from within my custom Visual Studio Extension.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:45:17+00:00Added an answer on June 2, 2026 at 1:45 am

    For creating a new File from a Visual Studio Extension (ToolWindowPane) first use the GetService method:

    // Get an instance of the currently running Visual Studio IDE
    DTE dte = (DTE)GetService(typeof(DTE));
    

    Second, ensure that a Solution is currently open, if no solution is open the File generation will not work:

    string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName);
    

    Third, generate the new file from the DTE object:

    dte.ItemOperations.NewFile(@"General\Visual C# Class", "ObjectOne", EnvDTE.Constants.vsViewKindTextView);
    

    After creating the new file use the following code to access the text of that file and replace it with your generated text:

    TextSelection txtSel = (TextSelection)dte.ActiveDocument.Selection;
    TextDocument txtDoc = (TextDocument)dte.ActiveDocument.Object("");
    
    txtSel.SelectAll();
    txtSel.Delete();
    txtSel.Insert("Hello World");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a c# project which includes a Text Template. I would like this
I have a project that I would like to start beta testing soon, it
I have this test page http://thechozenfew.net/projects/write_font.php that generates the text in the input box
We have a project that generates a code snippet that can be used on
I have a project that generates applications for two targets. One of the targets
I have a maven project that was generated by Spring Roo. Now I am
I have a .dll that I generated thorugh a C++ project. I have to
I have a .NET solution with an installer project that generates an MSI. One
On this site: http://stmc.modulemedia.co.uk/HossIntropia I have code that's generated by a CMS, I have
I have a django template that looks like this: <head> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js type=text/javascript></script> <script

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.