使用 Java 从共享点下载文件
Download files from sharepoint with Java
我是 Sharepoint 的新手,我正在尝试编写一个 java 程序来处理存储在 Sharepoint 文档库中的 csv 文件。我了解到共享点有一个新的 REST API,但它似乎需要通过应用程序注册进行身份验证,但我没有该共享点网站的管理员权限,因此我无法使用 REST API (?)。所以我选择用肥皂。
该文档库页面的 url 如下:
http://sharepoint/sites/pitpublishing/sales/Management_Distribution/Forms/AllItems.aspx?RootFolder=%2Fsites%2Fpitpublishing%2Fsales%2FManagement_Distribution%2FClar_Data&FolderCTID=0x012000C12183D9A264144BBD3D315xxxxxxx&View={F7D1xxx-62FD-428B-80EE-C44xxxxxx}
我对用 soap 消耗的共享点感到很困惑。我已经从
下载了 wsdl 文件
http://sharepoint/sites/pitpublishing/sales/_vti_bin/copy.asmx?WSDL
并为他们创建存根。我觉得应该有像getDocumentLibrary()这样的方法,是哪个目录操作文档库的,但是我只找到了和List、Copy和View相关的东西,很多和List相关。我不知道我应该给他们什么参数,我试过了
http://sharepoint/sites/pitpublishing/sales/Management_Distribution
但在 getListItems() 时总是出错:
SEVERE: Exception. See stacktrace.javax.xml.ws.soap.SOAPFaultException: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
如果我在同一站点下设置列表名称和列表,getListItems() 将 return null。
有没有人可以帮助我?非常感谢!
编辑:
我使用的代码实际上是来自 this blog 的教程代码。
public static void main(String[] args) {
// if(args.length != 3) {
// logger.log(Level.SEVERE, "This must be called with parameters: <userId> <password> <config file path>");
// return;
// }
try {
String userId = args[0];
String password = args[1];
WatcherConfig config = WatcherConfig.loadConfig("C:\Desktop\sharepoint\watcherConfig.xml");//; //args[2];args[2]);
Authenticator.setDefault(new FnmAuthenticator(userId, password));
Lists stub1 = new Lists(config.getListsWsdlUrl());
ListsSoap listService = stub1.getListsSoap();
List<SPDocument> docs = getDocuments(listService, config.getListName(), null, "100");
Copy stub2 = new Copy(config.getCopyWsdlUrl());
CopySoap copyService = stub2.getCopySoap();
//process document
for(SPDocument doc: docs) {
//make sure we download all attachments first
if(!doc.isEmail())
processDocument(listService, copyService, config, doc);
}
for(SPDocument doc: docs) {
//after we download all attachments, we process the emails.
if(doc.isEmail())
processDocument(listService, copyService, config, doc);
}
} catch (Exception e) {
System.out.println(e);
System.exit(1);
}
}
getDocuments() 的一部分在这里:
public static List<SPDocument> getDocuments(ListsSoap port, String listName,
ArrayList<String> listColumnNames, String rowLimit) {
List<SPDocument> docs = new ArrayList<SPDocument>();
if (port != null && listName != null
&& rowLimit != null) {
try {
// Here are additional parameters that may be set
String viewName = "{534xxxx-4D8B-4B1D-91E3-D2ECB6xxxxx}";
GetListItems.ViewFields viewFields = null;
GetListItems.Query query = null;
GetListItems.QueryOptions queryOptions = null;
String webID = "";
// Calling the List Web Service
GetListItemsResponse.GetListItemsResult result = port
.getListItems(listName, viewName, query, viewFields,
rowLimit, queryOptions, webID);
Object listResult = result.getContent().get(0);
......
Watcherconfig.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:watcherConfig xmlns:ns2="com.fanniemae.integration.sharepoint.clients">
<dispatcherList>
<dispatcherConfig matchingPattern="*" invokingCommand="D:\java\jdk15\bin\java.exe"/>
</dispatcherList>
<spDocumentArchiveUrl>http://sharepoint/sites/pitpublishing/sales/Management_Distribution/Clari_Data</spDocumentArchiveUrl>
<spDocumentInUrl>http://sharepoint/sites/pitpublishing/sales/Management_Distribution/Clari_Data</spDocumentInUrl>
<documentWorkingDir>C:\Desktop\sharepoint</documentWorkingDir>
<listsWsdlPath>C:\Desktop\sharepoint\Lists.wsdl</listsWsdlPath>
<copyWsdlPath>C:\Desktop\sharepoint\Copy.wsdl</copyWsdlPath>
<viewsWsdlPath>C:\Desktop\sharepoint\Views.wsdl</viewsWsdlPath>
<rowLimit>100000</rowLimit>
我终于可以使用 Python 访问这些文件了,请查看我的回答
我是 Sharepoint 的新手,我正在尝试编写一个 java 程序来处理存储在 Sharepoint 文档库中的 csv 文件。我了解到共享点有一个新的 REST API,但它似乎需要通过应用程序注册进行身份验证,但我没有该共享点网站的管理员权限,因此我无法使用 REST API (?)。所以我选择用肥皂。
该文档库页面的 url 如下:
http://sharepoint/sites/pitpublishing/sales/Management_Distribution/Forms/AllItems.aspx?RootFolder=%2Fsites%2Fpitpublishing%2Fsales%2FManagement_Distribution%2FClar_Data&FolderCTID=0x012000C12183D9A264144BBD3D315xxxxxxx&View={F7D1xxx-62FD-428B-80EE-C44xxxxxx}
我对用 soap 消耗的共享点感到很困惑。我已经从
下载了 wsdl 文件http://sharepoint/sites/pitpublishing/sales/_vti_bin/copy.asmx?WSDL
并为他们创建存根。我觉得应该有像getDocumentLibrary()这样的方法,是哪个目录操作文档库的,但是我只找到了和List、Copy和View相关的东西,很多和List相关。我不知道我应该给他们什么参数,我试过了
http://sharepoint/sites/pitpublishing/sales/Management_Distribution
但在 getListItems() 时总是出错:
SEVERE: Exception. See stacktrace.javax.xml.ws.soap.SOAPFaultException: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
如果我在同一站点下设置列表名称和列表,getListItems() 将 return null。
有没有人可以帮助我?非常感谢!
编辑:
我使用的代码实际上是来自 this blog 的教程代码。
public static void main(String[] args) {
// if(args.length != 3) {
// logger.log(Level.SEVERE, "This must be called with parameters: <userId> <password> <config file path>");
// return;
// }
try {
String userId = args[0];
String password = args[1];
WatcherConfig config = WatcherConfig.loadConfig("C:\Desktop\sharepoint\watcherConfig.xml");//; //args[2];args[2]);
Authenticator.setDefault(new FnmAuthenticator(userId, password));
Lists stub1 = new Lists(config.getListsWsdlUrl());
ListsSoap listService = stub1.getListsSoap();
List<SPDocument> docs = getDocuments(listService, config.getListName(), null, "100");
Copy stub2 = new Copy(config.getCopyWsdlUrl());
CopySoap copyService = stub2.getCopySoap();
//process document
for(SPDocument doc: docs) {
//make sure we download all attachments first
if(!doc.isEmail())
processDocument(listService, copyService, config, doc);
}
for(SPDocument doc: docs) {
//after we download all attachments, we process the emails.
if(doc.isEmail())
processDocument(listService, copyService, config, doc);
}
} catch (Exception e) {
System.out.println(e);
System.exit(1);
}
}
getDocuments() 的一部分在这里:
public static List<SPDocument> getDocuments(ListsSoap port, String listName,
ArrayList<String> listColumnNames, String rowLimit) {
List<SPDocument> docs = new ArrayList<SPDocument>();
if (port != null && listName != null
&& rowLimit != null) {
try {
// Here are additional parameters that may be set
String viewName = "{534xxxx-4D8B-4B1D-91E3-D2ECB6xxxxx}";
GetListItems.ViewFields viewFields = null;
GetListItems.Query query = null;
GetListItems.QueryOptions queryOptions = null;
String webID = "";
// Calling the List Web Service
GetListItemsResponse.GetListItemsResult result = port
.getListItems(listName, viewName, query, viewFields,
rowLimit, queryOptions, webID);
Object listResult = result.getContent().get(0);
......
Watcherconfig.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:watcherConfig xmlns:ns2="com.fanniemae.integration.sharepoint.clients">
<dispatcherList>
<dispatcherConfig matchingPattern="*" invokingCommand="D:\java\jdk15\bin\java.exe"/>
</dispatcherList>
<spDocumentArchiveUrl>http://sharepoint/sites/pitpublishing/sales/Management_Distribution/Clari_Data</spDocumentArchiveUrl>
<spDocumentInUrl>http://sharepoint/sites/pitpublishing/sales/Management_Distribution/Clari_Data</spDocumentInUrl>
<documentWorkingDir>C:\Desktop\sharepoint</documentWorkingDir>
<listsWsdlPath>C:\Desktop\sharepoint\Lists.wsdl</listsWsdlPath>
<copyWsdlPath>C:\Desktop\sharepoint\Copy.wsdl</copyWsdlPath>
<viewsWsdlPath>C:\Desktop\sharepoint\Views.wsdl</viewsWsdlPath>
<rowLimit>100000</rowLimit>
我终于可以使用 Python 访问这些文件了,请查看我的回答