File.CheckIn command and automated CheckIn<p>Hi all,<br/><br/>I need to programmatically Check-In a file in solution explorer.</p> <p>Scenario:<br/><br/>Visual Studio SDK 2008<br/><br/>C#</p> <p>Visual Source Safe 6.0</p> <p>Visual Studio 2008<br/><br/>VSPackage</p> <p>As i already read here: <a href="http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/8adae52a-46e9-4677-af1c-c6b451e720da">http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/8adae52a-46e9-4677-af1c-c6b451e720da</a> there are some different methods to do that, for instance:<br/><br/>- EnvDTE.SourceControl <br/>- IvSccXXX interfaces<br/><br/>but they doesn't contain an explicit CheckIn() method, as well explained by Craig Skibo in above link.<br/><br/>So, I'm trying Carlos Quintero' suggestion to use DTE.ExecuteCommand(&quot;File.CheckIn&quot;,...) but i get this error:<br/><br/><strong>Command &quot;File.CheckIn&quot; is not available.<br/></strong><br/>Here's my source code:</p> <div style="color:black;background-color:white"> <pre>EnvDTE.DTE dte = dTe <span style="color:blue">as</span> EnvDTE.DTE; <span style="color:green">//dTe is an correctly instaciated object of EnvDTE.DTE</span> <span style="color:blue">try</span> { <span style="color:green">//fullNameFile is my file FullName.</span> dte.ExecuteCommand(<span style="color:#a31515">&quot;File.CheckIn&quot;</span>, fullNameFile); } <span style="color:blue">catch</span> (Exception e) { <span style="color:blue">throw</span> <span style="color:blue">new</span> Exception(<span style="color:#a31515">&quot;Exception during CheckIn: &quot;</span> + e.Message); } <span style="color:blue">return</span> <span style="color:blue">true</span>; </pre> </div> <p>Is it because command File.CheckIn is not available for security?<br/>Is it because i put wrong arguments to the command?<br/>So, is there a way to CheckIn programmatically a ProjectItem by code with C# ??<br/><br/><br/>Any suggestion is welcome.<br/><br/>Bye<br/><br/></p> <hr class=sig> - Matteo Garzulino -© 2009 Microsoft Corporation. All rights reserved.Fri, 10 Jul 2009 13:28:21 Zb125d959-7a08-4305-811e-4fc6a9eb768ehttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#b125d959-7a08-4305-811e-4fc6a9eb768ehttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#b125d959-7a08-4305-811e-4fc6a9eb768eMatteo Garzulinohttp://social.msdn.microsoft.com/Profile/en-US/?user=Matteo%20GarzulinoFile.CheckIn command and automated CheckIn<p>Hi all,<br/><br/>I need to programmatically Check-In a file in solution explorer.</p> <p>Scenario:<br/><br/>Visual Studio SDK 2008<br/><br/>C#</p> <p>Visual Source Safe 6.0</p> <p>Visual Studio 2008<br/><br/>VSPackage</p> <p>As i already read here: <a href="http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/8adae52a-46e9-4677-af1c-c6b451e720da">http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/8adae52a-46e9-4677-af1c-c6b451e720da</a> there are some different methods to do that, for instance:<br/><br/>- EnvDTE.SourceControl <br/>- IvSccXXX interfaces<br/><br/>but they doesn't contain an explicit CheckIn() method, as well explained by Craig Skibo in above link.<br/><br/>So, I'm trying Carlos Quintero' suggestion to use DTE.ExecuteCommand(&quot;File.CheckIn&quot;,...) but i get this error:<br/><br/><strong>Command &quot;File.CheckIn&quot; is not available.<br/></strong><br/>Here's my source code:</p> <div style="color:black;background-color:white"> <pre>EnvDTE.DTE dte = dTe <span style="color:blue">as</span> EnvDTE.DTE; <span style="color:green">//dTe is an correctly instaciated object of EnvDTE.DTE</span> <span style="color:blue">try</span> { <span style="color:green">//fullNameFile is my file FullName.</span> dte.ExecuteCommand(<span style="color:#a31515">&quot;File.CheckIn&quot;</span>, fullNameFile); } <span style="color:blue">catch</span> (Exception e) { <span style="color:blue">throw</span> <span style="color:blue">new</span> Exception(<span style="color:#a31515">&quot;Exception during CheckIn: &quot;</span> + e.Message); } <span style="color:blue">return</span> <span style="color:blue">true</span>; </pre> </div> <p>Is it because command File.CheckIn is not available for security?<br/>Is it because i put wrong arguments to the command?<br/>So, is there a way to CheckIn programmatically a ProjectItem by code with C# ??<br/><br/><br/>Any suggestion is welcome.<br/><br/>Bye<br/><br/></p> <hr class=sig> - Matteo Garzulino -Tue, 23 Jun 2009 11:00:54 Z2009-06-23T11:01:47Zhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#1693ba61-6c0c-4fd1-8cb6-44e93ca8790bhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#1693ba61-6c0c-4fd1-8cb6-44e93ca8790bRong-Chun Zhanghttp://social.msdn.microsoft.com/Profile/en-US/?user=Rong-Chun%20ZhangFile.CheckIn command and automated CheckInHello Matteo,<br/><br/>When I File.CheckIn command in the Command Window, it will bring up the Check In Dialog and let the user to select the file which need to checkin. But if all the files in the solution is that same as in the Visual SourecSafe database, it will throw an error say &quot;Command 'File.CheckIn' is not available&quot;. You can try something like the following<br/><br/>dte.ExecuteCommand(<span style="color:#a31515">&quot;File.CheckIn&quot;<span style="color:#000000">);<br/><br/>Thanks,<br/>Rong-Chun Zhang</span></span><hr class="sig">Please mark the replies as answers if they help and unmark if they don't.<br/> <a href="http://cfx.codeplex.com/">Welcome to the All-In-One Code Framework</a>, a sample code project owned by the MSDN Forum Support team!Thu, 25 Jun 2009 07:11:01 Z2009-06-25T07:11:01Zhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#4e874c24-998e-438f-a565-4ae47332a15ahttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#4e874c24-998e-438f-a565-4ae47332a15aMatteo Garzulinohttp://social.msdn.microsoft.com/Profile/en-US/?user=Matteo%20GarzulinoFile.CheckIn command and automated CheckIn<p>Hi Rong-Chun,</p> <p>I tried to do what you suggested, but dte.ExecuteCommand() has this signature:</p> <pre lang="x-c#">_DTE.ExecuteCommand(string CommandName, string CommandArgs)</pre> <p>so, i must call it with CommandArgs argument. I tried with String.Empty, but i've always the same problem, &quot;Command 'File.CheckIn' is not available&quot;.<br/><br/>If you have any other suggestions even differents from using DTE.ExecuteCommand(), you're welcome!<br/><br/>Thanks,<br/><br/>Matteo.  </p><hr class="sig">- Matteo Garzulino -Thu, 02 Jul 2009 11:42:47 Z2009-07-02T11:42:47Zhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#a01f7f4a-c644-47f8-9ff5-46b08207c4adhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#a01f7f4a-c644-47f8-9ff5-46b08207c4adRong-Chun Zhanghttp://social.msdn.microsoft.com/Profile/en-US/?user=Rong-Chun%20ZhangFile.CheckIn command and automated CheckInHi Matteo,<br/> <br/> I have tried the following code in a Add in project with Visual Studio 2008 SP1, and the Check In Dialog will show.<br/> <br/>        _applicationObject.ExecuteCommand(&quot;File.CheckIn&quot;, String.Empty);<br/> <br/> As I said, in order to show the Check In Dialog, the following condition must be sure.<br/> <br/> 1.The project must be added to SourceSave database.<br/> 2. Source code file must be checked out or there are changes in source code file.<br/> <br/> Thanks,<br/> Rong-Chun Zhang<br/> <br/> <hr class=sig> Please mark the replies as answers if they help and unmark if they don't.<br/> <a href="http://cfx.codeplex.com/">Welcome to the All-In-One Code Framework</a> , a sample code project owned by the MSDN Forum Support team!Fri, 03 Jul 2009 12:07:42 Z2009-07-03T12:08:55Zhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#4e62131c-afd7-4a5d-b992-608d0d59ea3dhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#4e62131c-afd7-4a5d-b992-608d0d59ea3dMatteo Garzulinohttp://social.msdn.microsoft.com/Profile/en-US/?user=Matteo%20GarzulinoFile.CheckIn command and automated CheckInHi Rong-Chun,<br/><br/>thanks again for your answer.<br/><br/>I think that both conditions seems to be checked:<br/><br/>1-Surely my Solution (and Project, and ProjectItems...) is under Source Safe;<br/>2-About file changes i've got some more doubts: for instance, if during my vspackage execution I add some files to a Project, Project is automatically checked-out (this is the standard behaviour, even with adding files from VS &quot;Add New Item&quot;), so i think that even this condition should be sure at least for .csproj files.<br/><br/>Well, I'll try again on next monday... ;)<br/><br/>Good Week End.<br/><br/>Thanks,<br/><br/>Matteo.<hr class="sig">- Matteo Garzulino -Fri, 03 Jul 2009 18:31:28 Z2009-07-03T18:31:28Zhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#c3f5f72b-c767-4831-bfcf-78e3736e0f7bhttp://social.msdn.microsoft.com/Forums/en-US/vsx/thread/b125d959-7a08-4305-811e-4fc6a9eb768e#c3f5f72b-c767-4831-bfcf-78e3736e0f7bMatteo Garzulinohttp://social.msdn.microsoft.com/Profile/en-US/?user=Matteo%20GarzulinoFile.CheckIn command and automated CheckInHi Rong-Chun,<br/><br/><br/>I finally get command File.CheckIn to work!<br/><br/>Here what i did:<br/><br/> <pre lang="x-c#"> /// &lt;summary&gt; /// Esegue il comando CheckIn di un HierarchyItem precedentemente individuato. /// &lt;/summary&gt; /// &lt;param name=&quot;itemToCheck&quot;&gt;HierarchyItem di cui svolgere il check&lt;/param&gt; /// &lt;param name=&quot;mDte2&quot;&gt;Oggetto Dte.&lt;/param&gt; /// &lt;returns&gt;True: successo; Eccezione altrimenti.&lt;/returns&gt; public static bool CheckIn(UIHierarchyItem itemToCheck, DTE2 mDte2) { Commands c = mDte2.Commands; itemToCheck.Select(vsUISelectionType.vsUISelectionTypeSelect); foreach (Command co in c) { if (co.Name.Contains(&quot;File.CheckIn&quot;)) { System.Windows.Forms.MessageBox.Show(co.Name + &quot; - &quot; + co.IsAvailable + &quot; - &quot; + co.Guid + &quot; - &quot; + co.ID + &quot; - &quot; + co.LocalizedName); } } object outOb = null; object i = (itemToCheck as object); try { c.Raise(&quot;{AA8EB8CD-7A51-11D0-92C3-00A0C9138C45}&quot;, 11150, ref i, ref outOb); } catch (Exception) //Provo con il Check su richiesta. { c.Raise(&quot;{AA8EB8CD-7A51-11D0-92C3-00A0C9138C45}&quot;, 21014, ref i, ref outOb); } return true; }</pre> <p>First, i must get a UIHierarchyItem, Select it, then i can have the command to works using Command.Raise() method.<br/><br/>Note that code above is just a draft: i try to run File.CheckInSilent command, then if it fails I try File.CheckIn.<br/><br/>Note also that for both methods the first parameter is the GUID of the Command, the second one is the ID. You should use them when try to checkin using Command.Raise() method.<br/><br/>This seems to work very well during &quot;normal&quot; conditions; instead, i've got problems during or just after Project editing (for example after i add programmatically a projectitem). But this is partially off topic so i'll open a dedicated post.</p> <p>Hope that this would be helpful.<br/><br/>Thanks,</p> <p>Matteo.</p><hr class="sig">- Matteo Garzulino -Fri, 10 Jul 2009 08:48:07 Z2009-07-10T08:48:07Z