locked
Approve a document by Webservice RRS feed

  • Question

  • Hello,
    I'm trying to approve a document in sharepoint from the Webservices..

    When I do a CheckInFile() the document is in 'pending' .. How can I valid it by webservice ?
    In the Sharepoint Interface I need to click on Approve/Reject and select Approve ..

    Thanks for the info ^^
    Cbu
    Thursday, September 3, 2009 4:13 PM

Answers

  •                     XmlNode resultNode = l.UpdateListItems(Document_Library_Display_Name, (XmlElement)batchNode);

    Here is the point^^
    • Marked as answer by CbuatACM Friday, September 4, 2009 8:38 AM
    Friday, September 4, 2009 8:38 AM
  • You can use the following code that uses the lists web service and the UpdateListItems method. The key is to use the Cmd='Moderate'

     public static XmlNode UpdateListItemApprove()
     {
                listservice.Lists listProxy = new listservice.Lists();
    
    
                string xml = "<Batch OnError='Continue'><Method ID='1' Cmd='Moderate'><Field Name='ID'/><Field Name='FileRef'>http://basesmcdev2/sites/tester1/approvals/KL022030.lic</Field><Field Name=\"_ModerationStatus\" >0</Field></Method></Batch>";
    
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
    
                XmlNode batchNode = doc.SelectSingleNode("//Batch");
    
                listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";
                listProxy.UseDefaultCredentials = true;
    
                XmlNode resultNode = listProxy.UpdateListItems("approvals", batchNode);
    
                return resultNode;
    
    
    }

    certdev.com
    • Marked as answer by CbuatACM Friday, September 4, 2009 8:38 AM
    Thursday, September 3, 2009 8:17 PM

All replies

  • You can use the following code that uses the lists web service and the UpdateListItems method. The key is to use the Cmd='Moderate'

     public static XmlNode UpdateListItemApprove()
     {
                listservice.Lists listProxy = new listservice.Lists();
    
    
                string xml = "<Batch OnError='Continue'><Method ID='1' Cmd='Moderate'><Field Name='ID'/><Field Name='FileRef'>http://basesmcdev2/sites/tester1/approvals/KL022030.lic</Field><Field Name=\"_ModerationStatus\" >0</Field></Method></Batch>";
    
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xml);
    
                XmlNode batchNode = doc.SelectSingleNode("//Batch");
    
                listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";
                listProxy.UseDefaultCredentials = true;
    
                XmlNode resultNode = listProxy.UpdateListItems("approvals", batchNode);
    
                return resultNode;
    
    
    }

    certdev.com
    • Marked as answer by CbuatACM Friday, September 4, 2009 8:38 AM
    Thursday, September 3, 2009 8:17 PM
  • Why they dont expose Approve method in the Sharepoint DLL :P

    I will try your example..
    Will come back in a few minutes

    Thanks
    Friday, September 4, 2009 7:37 AM
  • Humm .. I got an exception:

    System.ServiceModel.FaultException: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.

    Server stack trace:
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at UT_Sharepoint.spLists.ListsSoap.UpdateListItems(UpdateListItemsRequest request)
       at UT_Sharepoint.spLists.ListsSoapClient.UT_Sharepoint.spLists.ListsSoap.UpdateListItems(UpdateListItemsRequest request) in D:\My Documents\Visual Studio 2008\Projects\UT_Sharepoint\UT_Sharepoint\Service References\spLists\Reference.cs:line 2334
       at UT_Sharepoint.spLists.ListsSoapClient.UpdateListItems(String listName, XmlElement updates) in D:\My Documents\Visual Studio 2008\Projects\UT_Sharepoint\UT_Sharepoint\Service References\spLists\Reference.cs:line 2342
       at SharePointTest.UnitTest1.TestApprove() in D:\My Documents\Visual Studio 2008\Projects\UT_Sharepoint\UT_Sharepoint\UnitTest1.cs:line 597


    there is my code :
                        StringBuilder sbQuery = new StringBuilder();
                        sbQuery.Append("<Batch OnError='Continue'>");
                        sbQuery.Append("    <Method ID='1' Cmd='Moderate'>");
                        sbQuery.Append("        <Field Name='ID'/>");
                        sbQuery.Append("        <Field Name='FileRef'>http://SPSServer:654/SubSite/pages/about.aspx</Field>");
                        sbQuery.Append("        <Field Name=\"_ModerationStatus\" >0</Field>");
                        sbQuery.Append("    </Method>");
                        sbQuery.Append("</Batch>");

                        string xml = sbQuery.ToString();
                           

                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(xml);

                        XmlNode batchNode = doc.SelectSingleNode("//Batch");

                        XmlNode resultNode = l.UpdateListItems("approvals", (XmlElement)batchNode);

    In the UpdateListItems I need an XmlElement .. and not an XmlNode but I think it's correct..
    any idea ?
    Friday, September 4, 2009 8:06 AM
  • Ok my ListName is not correct..
    Trying again ..
    Friday, September 4, 2009 8:32 AM
  •                     XmlNode resultNode = l.UpdateListItems(Document_Library_Display_Name, (XmlElement)batchNode);

    Here is the point^^
    • Marked as answer by CbuatACM Friday, September 4, 2009 8:38 AM
    Friday, September 4, 2009 8:38 AM
  • I tried this and it's working.. (XmlElement) did the magik.
    Regards,
    Venkatesh R
    /* My Code Runs in Visual Studio 2010 */
    http://geekswithblogs.net/venkatx5/
    MCTS : SharePoint 2010, Application Development | MCPD : SharePoint 2010 Developer
    Friday, July 15, 2011 12:04 PM