使用来自32位应用程序的SPSite访问64位SharePoint

时间:2008-10-30 14:27:18

标签: sharepoint

我创建了一个以32位模式运行的批处理作业,因为它使用32位COM目标,这需要连接到SharePoint以进行列表更新。 它在我的开发环境中工作,因为它是完整的32位。但是在我的测试和制作环境中,我们使用64位SharePoint,这是我从SPSite获得的:

System.IO.FileNotFoundException: 
  The Web application at http://<my sp host>/ could not be found. 
  Verify that you have typed the URL correctly. 
  If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.

at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri req...

这就是我的工作

        using (SPSite site = new SPSite(_url))
        {
            using (SPWeb web = site.OpenWeb())
            {
                try
                {
                    SPList list = web.Lists[new Guid(_listID)];
                    SPListItem item = list.GetItemById(id);
                    item[field] = value;
                    item.SystemUpdate(false);
                }
                catch (Exception x)
                {
                    log.Error(x);
                }
            }
        }

2 个答案:

答案 0 :(得分:6)

您只需要在64位进程中运行批处理作业。问题是SharePoint在您的测试和生产环境中有许多COM对象,这些对象在64位编译。 SPSite和SPWeb对象实际上包装了COM对象,这就是它们在32位进程中失败的原因。

可以通过其Web服务而不是对象模型与SharePoint进行交互。

答案 1 :(得分:1)

我不认为这是一个32/64位问题,因为我在32位和64位上进行开发的情况相同。 (实际上,我们运行的是32位和64位WFE')

由于从SPSite构造函数抛出异常,我会进一步调查,您运行代码的机器(SP框)是否实际识别该URL。