有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何在java中获取sharepoint项目的listItemId值

我正在尝试使用java中sharepoint的ListsSoap web服务来获取当前位于sharepoint上的docx文件的附件。并试图将docx文件下载到我的本地磁盘。然而,现在我在以下代码中尝试从sharepoint获取XML时出错

我明白了 “Microsoft”类型的例外。SharePoint。SoapServer。引发了“SoapServerException”

SharepointReference sharepointReference = new SharepointReference();
ListsSoap listsSoap = sharepointReference.getListAuth("sharepointId","sharepointPassword");
GetAttachmentCollectionResponse.GetAttachmentCollectionResult x = listsSoap.getAttachmentCollection("listName", "28");

参数中的“28”指的是listitems的ows_ID列的值。我不确定这是否是getAttachmentCollection的第二个参数获取的列表项的listItemId

有人知道是因为身份验证问题还是因为listItemId无效而抛出错误吗


共 (1) 个答案

  1. # 1 楼答案

    如何设置和验证的逻辑在SharepointReference类及其getListAuth方法中被屏蔽。由于不知道逻辑,我们无法确定原因。下面的逻辑是通过web服务访问SharePoint列表内容的典型方法。你可以试试这个这还没有准备好编译,因为我从我的解决方案中借用了一些片段(由于IP原因,我无法共享这些片段)

    public void GetAttachments {
        String endPoint = "http://YourSiteUrlIncludingTheSubweb"+"/_vti_bin/Lists.asmx";
    
        //set proper authentication
        java.net.CookieManager cm = new java.net.CookieManager();
        java.net.CookieHandler.setDefault(cm);
        Authenticator.setDefault(new SPAuthenticator());
    
        //Connect to list
        Lists service = new Lists(new URL(endPoint+"?wsdl"),
                new QName("http://schemas.microsoft.com/sharepoint/soap/", "Lists"));
        ListsSoap soap = service.getListsSoap();
        BindingProvider bp = (BindingProvider) soap;
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "domain\username");
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
        bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endPoint);
    
        //get attachments
        port.getAttachmentCollection(...)
        .
        .
        .
    }
    

    这是我们的垃圾邮件认证者。java类

    public class SPAuthenticator extends Authenticator {
    
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("domain\username","password".toCharArray());
        }
    }
    

    希望这有帮助