Cообщество разработчиков на платформе Microsoft > Форумы > SharePoint - Development and Programming > I cannot approve the publishing page (submitted for approval), could you please advise my code?
Задайте вопросЗадайте вопрос
 

ОтвеченоI cannot approve the publishing page (submitted for approval), could you please advise my code?

  • 3 июля 2009 г. 12:23Hello World August Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    Hi all ^^,

    I wanna override approve button (the qucik access buttion in Page Editing Tool Bar),
    the basis approve function must be kept and just need to add some custom action...


    When I try to add the following code to act the work flow like SharePoint default action ( for Status :   Waiting for approval ),
    I cannot approve that without any exception:

     SPSite spSite = new SPSite(strPageUrl);
    
     SPWeb spWeb = spSite.OpenWeb();
    
    //Test Only - Start ^o^
    
     if (PublishingWeb.IsPublishingWeb(spWeb))
                        {
                            spWeb.AllowUnsafeUpdates = true;
    
    //Test Only - End XD
    
    //Approve Work Flow - Fake - Orz
    
                            SPListItem listItem = SPContext.Current.ListItem;
    
                            if (PublishingPage.IsPublishingPage(listItem))
                            {
    
                                Common.WriteTxtFile("Is Publishing Page", strOutPutPath_Log);
    
                                PublishingPage page = PublishingPage.GetPublishingPage(listItem);
    
                                if (page.ListItem.ModerationInformation.Status.Equals(SPModerationStatusType.Draft) ||
    
                                    page.ListItem.ModerationInformation.Status.Equals(SPModerationStatusType.Pending))
    
                                {
    
                                    string checkInComment = "Custom Approve Action";
    
    
    SPModerationInformation modInfo = listItem.ModerationInformation; modInfo.Status = SPModerationStatusType.Approved;
                                    modInfo.Comment = checkInComment;
                                    listItem.Update(); //Approve Work Flow - Fake - Approve Failed without Exception - >o< page.ListItem.File.Approve(checkInComment); //Approve Work Flow - Fake - Publish Failed without Exception - >o< page.ListItem.File.Publish(checkInComment); } } // Test only spWeb.AllowUnsafeUpdates = false; }
    Could you please advise me for above coding?

    Moreover, my testing SharePoint seems has the "send E-mail" workflow and it will act with approve workflow,
    if the page approved in code (e.g. if Approve() is OK) , Is Approve() will trigger  "send E-mail" workflow  or not?
    If not, how can I do?

    Thank you very much for any help or advice.



    .NET Beginner 3.5

Ответы

  • 3 июля 2009 г. 17:39RaghavanS Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     Отвечено
    Hi,

    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]

    try
    {
    page.ListItem.ModerationInformation.Status = SPModerationStatusType.Approved;
    page.ListItem.ModerationInformation.Comment = checkInComment;
    page.ListItem.Update();

    }
    catch(Exception ex)
    {
    throw ex;
    }
    try
    {
     page.ListItem.File.Approve(checkInComment);
     page.ListItem.File.Publish(checkInComment);
     //I THINK YOU ARE MISSING AN UPDATE STATEMENT HERE
    }
    catch(Exception ex)
    {
    throw ex;
    }

    Hope this helps
    Raghavan

Все ответы