title: Example of usage for IVsProject.AddItem
body: <p>Anybody has example for <code>IVsProject.AddItem</code> till now I have done following but did not understand how to use <code>IVsProject.AddItem</code> and <code>msdn</code> does not have any example.</p>
  
  <pre><code>private void MenuItemCallback(object sender, EventArgs e)
  {
     IVsSolution solutionService = GetService(typeof(SVsSolution)) as IVsSolution;
     // get all projects in solution
     IEnumHierarchies enumHierarchies = null;
     Guid guid = Guid.Empty;
     ErrorHandler.ThrowOnFailure(solutionService.GetProjectEnum(
                                    (uint)__VSENUMPROJFLAGS.EPF_ALLINSOLUTION,
                                    ref guid,
                                    out enumHierarchies));
     //Loop all projects found
     if (enumHierarchies != null)
     {
        // Loop projects found
        IVsHierarchy[] hierarchy = new IVsHierarchy[1];
        uint fetched = 0;
  
        while (enumHierarchies.Next(1, hierarchy, out fetched) == VSConstants.S_OK
             &amp;&amp; fetched == 1)
        {                   
           Guid projectGuid;
           ErrorHandler.ThrowOnFailure(hierarchy[0].GetGuidProperty(
                                          VSConstants.VSITEMID_ROOT,
                                          (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
                                          out projectGuid));
           IVsProject project = (IVsProject)hierarchy[0];
           project.AddItem(VSConstants.VSITEMID_ROOT,
                           VSADDITEMOPERATION.VSADDITEMOP_OPENFILE,
                           1,
                           ...)
  
        }
     }            
  }
  </code></pre>
  
  <p>following is also not working using <code>DTE</code></p>
  
  <pre><code>private void MenuItemCallback(object sender, EventArgs e)
  {
     //GemFireWizardForm form = new GemFireWizardForm();
     //form.ShowDialog();
     //Get the solution service
  
     IVsSolution solutionService = GetService(typeof(SVsSolution)) as IVsSolution;
     // get all projects in solution
     IEnumHierarchies enumHierarchies = null;
     Guid guid = Guid.Empty;
     ErrorHandler.ThrowOnFailure(solutionService.GetProjectEnum(
                                    (uint)__VSENUMPROJFLAGS.EPF_ALLINSOLUTION,
                                    ref guid,
                                    out enumHierarchies));
     //Loop all projects found
     if (enumHierarchies != null)
     {
        // Loop projects found
        IVsHierarchy[] hierarchy = new IVsHierarchy[1];
        uint fetched = 0;
        Guid projectGuid = Guid.Empty;
        while (enumHierarchies.Next(1, hierarchy, out fetched) == VSConstants.S_OK
             &amp;&amp; fetched == 1)
        {
           ErrorHandler.ThrowOnFailure(hierarchy[0].GetGuidProperty(
                                          VSConstants.VSITEMID_ROOT,
                                          (int)__VSHPROPID.VSHPROPID_ProjectIDGuid,
                                          out projectGuid));
        }
  
        IVsHierarchy ppHierarchy = null;
        IVsSolution solution = (IVsSolution)GetService(typeof(SVsSolution));
        Int32 result = solution.GetProjectOfGuid(ref projectGuid, out ppHierarchy);
  
        if (ppHierarchy != null &amp;&amp; result == VSConstants.S_OK)
        {
           Object automationObject = null;
           ppHierarchy.GetProperty(VSConstants.VSITEMID_ROOT,
                                   (Int32)__VSHPROPID.VSHPROPID_ExtObject,
                                   out automationObject);
  
           if (automationObject != null)
           {
              EnvDTE.SolutionClass sc = automationObject as EnvDTE.SolutionClass;
              EnvDTE.Projects projects = sc.Projects;
              EnvDTE.Project project = projects.Item(1);
              EnvDTE.ProjectItems pitems = project.ProjectItems;
  
              pitems.AddFromFileCopy(@"e:\avinash\test.cpp");
           }
        }
     }            
  }
  </code></pre>
  
  <p><code>sc</code> is coming as <code>null</code></p>