我有一个使用表单认证的sharepoint服务器。现在我想连接到该服务器,通过列表的Webservice获取所有的列表。
我可以连接到使用Windows身份验证的SharePoint服务器,但是我不能使用FormsAuthentication。
你能帮我弄清楚吗?
public static Lists CreateSharepointService(string sharepointHost)
{
Lists wssSrvc = new Lists();
if (sharepointHost.EndsWith("/"))
wssSrvc.Url = sharepointHost + "_vti_bin/Lists.asmx";
else
wssSrvc.Url = sharepointHost + "/_vti_bin/Lists.asmx";
return wssSrvc;
}
public static Lists CreateSharepointService(string sharepointHost, string sharepointUsername, string sharepointPassword, string sharepointDomain)
{
NetworkCredential credential = new NetworkCredential(sharepointUsername, sharepointPassword, sharepointDomain);
Lists wssSrvc = CreateSharepointService(sharepointHost);
wssSrvc.Credentials = credential;
return wssSrvc;
}
您可以添加一个Service Reference或使用wsdl.exe创建一个代理类,并使用下面的代码从某个sharepoint站点获取所有列表:
XmlNode ndLists = listService.GetListCollection();
让我知道如果你有错误调用GetListCollection()
方法。只要您能够通过正确的凭据,这就应该可以工作。:)