在SharePoint 2010中,在站点Web服务中有一个新方法CreateWeb,目的是创建新的SharePoint子站点。但是,它有很多问题 - 至少,这是我的经验。下面是应利用Web服务和它的方法正确的代码:如何使用Web服务在SharePoint 2010中创建新的子站点?
Uri site = new Uri("http://sp2010site/");
string webServicePath = "_vti_bin/Sites.asmx";
string webServiceUrl = Path.Combine(site.AbsoluteUri, webServicePath);
Sites webService = new Sites();
webService.Credentials = CredentialCache.DefaultNetworkCredentials;
webService.Url = webServiceUrl;
//the following line creates the sub site
string result = webService.CreateWeb("newsite", "New Site", "Site desc", "STS#0",
1033, true, 1033, true, 1033, true, true, true, true, true, true, true);
下面的代码返回SOAP异常,如果发生了什么错误(例如,一个子网站地址为“newsite”已经存在,或者指定的模板不存在)。
如果一切正常,则会触发一条InvalidOperation异常,并显示消息“XML文档(1,310)中存在错误。”,但该站点实际上已创建!
如果一切正常,但我使用我自己的解决方案而不是非默认的SharePoint模板(例如团队网站,即STS#0),我会得到一个Soap异常并且不会创建网站。
到目前为止这是一个很糟糕的经历。请在SP 2010中发布您的子站点创建经验,如果您有任何问题,请发布解决方案以解决这些问题。干杯!
是啊,你说得对,模板字符串参数应为提供{site_guid} #template_name。但是,InvalidExceptio每次调用CreateWeb方法时都会触发(并且该网站确实已创建)。所以,问题依然存在。您是否能够使用CreateWeb方法创建一个没有任何异常的站点?这是一个拖累...我知道它在测试版,但仍然... :) – Boris 2010-01-20 20:15:22
它在这里工作得很好。我们确实遇到了一个未能加载的网站模板的问题 - 但它也无法在正常机制下加载。希望你找到解决方案。 – 2010-01-25 06:09:12
InvalidException触发是Microsoft确认的错误。那么,我希望他们能够在SharePoint 2010的官方版本中修复它。 – Boris 2010-03-11 15:24:18