I cannot approve the publishing page (submitted for approval), could you please advise my code?Hi all ^^,<br/><br/>I wanna override approve button (the qucik access buttion in Page Editing Tool Bar), <br/>the basis approve function must be kept and just need to add some custom action...<br/><br/><br/>When I try to add the following code to act the work flow like SharePoint default action ( for Status :   Waiting for approval ),<br/>I cannot approve that without any exception:<br/><br/> <div style="color:black;background-color:white"> <pre> SPSite spSite = <span style="color:blue">new</span> SPSite(strPageUrl); SPWeb spWeb = spSite.OpenWeb(); <span style="color:green">//Test Only - Start ^o^</span> <span style="color:blue">if</span> (PublishingWeb.IsPublishingWeb(spWeb)) { spWeb.AllowUnsafeUpdates = <span style="color:blue">true</span>; <span style="color:green">//Test Only - End XD</span> <span style="color:green">//Approve Work Flow - Fake - Orz</span> SPListItem listItem = SPContext.Current.ListItem; <span style="color:blue">if</span> (PublishingPage.IsPublishingPage(listItem)) { Common.WriteTxtFile(<span style="color:#a31515">&quot;Is Publishing Page&quot;</span>, strOutPutPath_Log); PublishingPage page = PublishingPage.GetPublishingPage(listItem); <span style="color:blue">if</span> (page.ListItem.ModerationInformation.Status.Equals(SPModerationStatusType.Draft) || page.ListItem.ModerationInformation.Status.Equals(SPModerationStatusType.Pending)) { <span style="color:blue">string</span> checkInComment = <span style="color:#a31515">&quot;Custom Approve Action&quot;</span>; <br/> SPModerationInformation modInfo = listItem.ModerationInformation; modInfo.Status = SPModerationStatusType.Approved;<br/>                                modInfo.Comment = checkInComment;<br/>                                listItem.Update(); <span style="color:green">//Approve Work Flow - Fake - Approve Failed without Exception - &gt;o&lt;</span> page.ListItem.File.Approve(checkInComment); <span style="color:green">//Approve Work Flow - Fake - Publish Failed without Exception - &gt;o&lt;</span> page.ListItem.File.Publish(checkInComment); } } // Test only spWeb.AllowUnsafeUpdates = <span style="color:blue">false</span>; } </pre> </div> Could you please advise me for above coding? <br/><br/>Moreover, my testing SharePoint seems has the &quot;send E-mail&quot; workflow and it will act with approve workflow,<br/>if the page approved in code (e.g. if Approve() is OK) , Is Approve() will trigger  &quot;send E-mail&quot; workflow  or not? <br/>If not, how can I do?<br/><br/>Thank you very much for any help or advice.<br/><br/><br/> <hr class=sig> .NET Beginner 3.5© 2009 Microsoft Corporation. All rights reserved.Fri, 17 Jul 2009 10:44:01 Zde73114e-07a7-47f0-9adf-6f7ef13d375chttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#de73114e-07a7-47f0-9adf-6f7ef13d375chttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#de73114e-07a7-47f0-9adf-6f7ef13d375cHello World Augusthttp://social.technet.microsoft.com/Profile/en-US/?user=Hello%20World%20AugustI cannot approve the publishing page (submitted for approval), could you please advise my code?Hi all ^^,<br/><br/>I wanna override approve button (the qucik access buttion in Page Editing Tool Bar), <br/>the basis approve function must be kept and just need to add some custom action...<br/><br/><br/>When I try to add the following code to act the work flow like SharePoint default action ( for Status :   Waiting for approval ),<br/>I cannot approve that without any exception:<br/><br/> <div style="color:black;background-color:white"> <pre> SPSite spSite = <span style="color:blue">new</span> SPSite(strPageUrl); SPWeb spWeb = spSite.OpenWeb(); <span style="color:green">//Test Only - Start ^o^</span> <span style="color:blue">if</span> (PublishingWeb.IsPublishingWeb(spWeb)) { spWeb.AllowUnsafeUpdates = <span style="color:blue">true</span>; <span style="color:green">//Test Only - End XD</span> <span style="color:green">//Approve Work Flow - Fake - Orz</span> SPListItem listItem = SPContext.Current.ListItem; <span style="color:blue">if</span> (PublishingPage.IsPublishingPage(listItem)) { Common.WriteTxtFile(<span style="color:#a31515">&quot;Is Publishing Page&quot;</span>, strOutPutPath_Log); PublishingPage page = PublishingPage.GetPublishingPage(listItem); <span style="color:blue">if</span> (page.ListItem.ModerationInformation.Status.Equals(SPModerationStatusType.Draft) || page.ListItem.ModerationInformation.Status.Equals(SPModerationStatusType.Pending)) { <span style="color:blue">string</span> checkInComment = <span style="color:#a31515">&quot;Custom Approve Action&quot;</span>; <br/> SPModerationInformation modInfo = listItem.ModerationInformation; modInfo.Status = SPModerationStatusType.Approved;<br/>                                modInfo.Comment = checkInComment;<br/>                                listItem.Update(); <span style="color:green">//Approve Work Flow - Fake - Approve Failed without Exception - &gt;o&lt;</span> page.ListItem.File.Approve(checkInComment); <span style="color:green">//Approve Work Flow - Fake - Publish Failed without Exception - &gt;o&lt;</span> page.ListItem.File.Publish(checkInComment); } } // Test only spWeb.AllowUnsafeUpdates = <span style="color:blue">false</span>; } </pre> </div> Could you please advise me for above coding? <br/><br/>Moreover, my testing SharePoint seems has the &quot;send E-mail&quot; workflow and it will act with approve workflow,<br/>if the page approved in code (e.g. if Approve() is OK) , Is Approve() will trigger  &quot;send E-mail&quot; workflow  or not? <br/>If not, how can I do?<br/><br/>Thank you very much for any help or advice.<br/><br/><br/> <hr class=sig> .NET Beginner 3.5Fri, 03 Jul 2009 12:23:30 Z2009-07-03T12:38:14Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#ee2d2856-e435-4d26-9805-35f2de982ca3http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#ee2d2856-e435-4d26-9805-35f2de982ca3Naresh kilaru [MCTS]http://social.technet.microsoft.com/Profile/en-US/?user=Naresh%20kilaru%20%5bMCTS%5dI cannot approve the publishing page (submitted for approval), could you please advise my code?i think you dont have permissions to approve. use Runwithelevated privilages code to approve the page<br/> <br/>Fri, 03 Jul 2009 12:31:15 Z2009-07-03T12:31:15Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#6aeaede1-39a8-43db-bfbc-b4b62faaac5bhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#6aeaede1-39a8-43db-bfbc-b4b62faaac5bHello World Augusthttp://social.technet.microsoft.com/Profile/en-US/?user=Hello%20World%20AugustI cannot approve the publishing page (submitted for approval), could you please advise my code?Thank you for your help, but the statue still cannot be changed by following code... &gt;O&lt;<br/><br/><br/> <pre lang="x-c#"> SPSecurity.RunWithElevatedPrivileges( delegate() { SPSite spSite = new SPSite(strPageUrl); SPWeb spWeb = spSite.OpenWeb(); if (PublishingWeb.IsPublishingWeb(spWeb)) { spWeb.AllowUnsafeUpdates = true; SPListItem listItem = SPContext.Current.ListItem; if (PublishingPage.IsPublishingPage(listItem)) { Common.WriteTxtFile(&quot;Is Publishing Page&quot;, strOutPutPath_Log); PublishingPage page = PublishingPage.GetPublishingPage(listItem); Common.WriteTxtFile(&quot;ModerationInformation Status - &quot; + page.ListItem.ModerationInformation.Status, strOutPutPath_Log); if (page.ListItem.ModerationInformation.Status.Equals(SPModerationStatusType.Draft) || page.ListItem.ModerationInformation.Status.Equals(SPModerationStatusType.Pending)) { string checkInComment = &quot;Custom Approve Action&quot;; Common.WriteTxtFile(&quot;Try to publish...&quot;, strOutPutPath_Log); SPModerationInformation modInfo = listItem.ModerationInformation; page.ListItem.ModerationInformation.Status = SPModerationStatusType.Approved; page.ListItem.ModerationInformation.Comment = checkInComment; page.ListItem.Update(); page.ListItem.File.Approve(checkInComment); page.ListItem.File.Publish(checkInComment); Common.WriteTxtFile(&quot;No error, no break, no exception and no changes!&quot;); SPModerationInformation modInfo = listItem.ModerationInformation; <br/> } } spWeb.AllowUnsafeUpdates = false; } } );</pre> <br/><br/> <hr class=sig> .NET Beginner 3.5 (~.^)Fri, 03 Jul 2009 12:51:25 Z2009-07-03T13:07:59Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#e88c6ef9-1999-4293-ba23-f87e2b8e49b7http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#e88c6ef9-1999-4293-ba23-f87e2b8e49b7Naresh kilaru [MCTS]http://social.technet.microsoft.com/Profile/en-US/?user=Naresh%20kilaru%20%5bMCTS%5dI cannot approve the publishing page (submitted for approval), could you please advise my code?What error exactly u r getting while approvingFri, 03 Jul 2009 12:55:08 Z2009-07-03T12:55:08Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#b88d1e06-a69d-4dfe-909b-85237e93e869http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#b88d1e06-a69d-4dfe-909b-85237e93e869Hello World Augusthttp://social.technet.microsoft.com/Profile/en-US/?user=Hello%20World%20AugustI cannot approve the publishing page (submitted for approval), could you please advise my code?No error, no break, no exception after run the code .......  but no changes too  (~.~) <br/><br/>And I can see the log file include the message and it created by:<br/><br/>Common.WriteTxtFile(<span style="color:#a31515">&quot;No error, no break, no exception and no changes!&quot;</span>);<br/><br/><br/> <hr class=sig> .NET Beginner 3.5 (~.^)Fri, 03 Jul 2009 13:05:21 Z2009-07-03T13:09:25Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#a5067334-3821-4bc2-9ca4-c3adfdccbcd2http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#a5067334-3821-4bc2-9ca4-c3adfdccbcd2Naresh kilaru [MCTS]http://social.technet.microsoft.com/Profile/en-US/?user=Naresh%20kilaru%20%5bMCTS%5dI cannot approve the publishing page (submitted for approval), could you please advise my code?After Page.ListItem.Update()<br/> <br/> First Check in tht file then publish &amp; approve.<br/> <br/> Then do <p align=left><span style="color:#0000ff">publishingWeb.Update();</span></p> <p align=left><span style="color:#0000ff">and then<br/> </span></p> <p align=left><span style="color:#0000ff">subweb.Update();</span></p> <p align=left> </p> <p align=left><span style="color:#0000ff">After all these dispose all the webs<br/> </span></p> <p align=left><span style="color:#0000ff"><br/> </span></p>Fri, 03 Jul 2009 13:19:07 Z2009-07-03T13:22:47Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#f8e77cd9-6a4d-4946-8cc5-fae2a8ea2cf1http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#f8e77cd9-6a4d-4946-8cc5-fae2a8ea2cf1RaghavanShttp://social.technet.microsoft.com/Profile/en-US/?user=RaghavanSI cannot approve the publishing page (submitted for approval), could you please advise my code?Hi,<br/><br/>Kindly apply a try catch block for the following code.. like [I am typing this from a notepad, kindly check the code in Visual Studio]<br/><br/>try<br/>{<br/>page.ListItem.ModerationInformation.Status = SPModerationStatusType.Approved;<br/>page.ListItem.ModerationInformation.Comment = checkInComment;<br/>page.ListItem.Update();<br/><br/>}<br/>catch(Exception ex)<br/>{<br/>throw ex;<br/>}<br/>try<br/>{<br/> page.ListItem.File.Approve(checkInComment);<br/> page.ListItem.File.Publish(checkInComment);<br/> //I THINK YOU ARE MISSING AN UPDATE STATEMENT HERE<br/>}<br/>catch(Exception ex)<br/>{<br/>throw ex;<br/>}<br/><br/>Hope this helps<hr class="sig">RaghavanFri, 03 Jul 2009 17:39:09 Z2009-07-03T17:39:09Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#85871919-c141-4389-b698-d1724d2ccca8http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#85871919-c141-4389-b698-d1724d2ccca8Hello World Augusthttp://social.technet.microsoft.com/Profile/en-US/?user=Hello%20World%20AugustI cannot approve the publishing page (submitted for approval), could you please advise my code?Thanks for your kindly advice,<br/><br/>I tested the following code first, it's work ... but...<br/><br/> <pre lang="x-c#">bool flagApproved = false;<br/>SPFile page.ListItem.File = page.ListItem.File<br/>publishFile.CheckOut(); // 101<br/> publishFile.CheckIn(checkInComment,SPCheckinType.MajorCheckIn); //102 publishFile.Publish(checkInComment); // 103 publishFile.Approve(checkInComment); // 104<br/><br/><br/><br/><br/><br/><br/></pre> My queestion  is :<br/><br/>1. Can I don't check out and just publish it as Major Version? (It cannot work if just insert line 103 and 104)<br/>2. Can I check the page/file status in SPFile  ?<br/><br/>e.g. I want to set flagApproved = true if the page approved, how can I check the status....? (e.g. Is Major Version ?)<br/><br/>3. Is the above coding risky? Could you please let me know iif you have any solution is better than above coding...<br/><br/>4. I think my concept is not clear for Publishng Page Approval Workflow ...<br/>4.1  Why I just can aprrove it by using SPFile method? And why I failed to publish page in Page Editing Toolbar by using Page.ListItem.XXX or Page.XXX() etc.<br/><br/>Thank you very much for any help or advice.<br/><br/> <hr class=sig> .NET Beginner 3.5 (~.^)Sun, 05 Jul 2009 08:13:51 Z2009-07-05T08:15:01Zhttp://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#d27ad129-4846-48bc-974a-9d9acb2a0956http://social.technet.microsoft.com/Forums/en-US/sharepointdevelopment/thread/de73114e-07a7-47f0-9adf-6f7ef13d375c#d27ad129-4846-48bc-974a-9d9acb2a0956Naresh kilaru [MCTS]http://social.technet.microsoft.com/Profile/en-US/?user=Naresh%20kilaru%20%5bMCTS%5dI cannot approve the publishing page (submitted for approval), could you please advise my code?You can't approve a page with out it being checked out.<br/> You can know the page status. You already checking in your code if it is not in draftmode and not in pening state<br/> <br/>Mon, 06 Jul 2009 11:21:56 Z2009-07-06T11:21:56Z