基于SharePoint 2010的控制台应用程序常见问题

通过VS2010编写SharePoint 2010的控制台应用程序时,遇到一些很奇怪的问题:

1、程序需要使用Microsoft.SharePoint.dll,可是居然在添加引用时在列表中找不到。

解决办法:创建项目时没有选择正确的.NET Framework版本,SharePoint 2010是基于.Net Framework 3.5的,而VS2010默认是4.0。

2、编译时,明明网站地址没有错,却总是报错,说找不到。如下图:

FileNotFoundException was unhandled 错误

内容:The Web Application at http://sp2010u/sites/contoso 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.

出错原因与解决


查看了一下编译配置,默认是x86,而且没有其他可选。

而SharePoint 2010是64位的。这里,选择新建一个解决方案平台:

这里平台名称就用Any CPU,从已有平台拷贝设置选择<Empty>。(看到后面提到的参考资料里写的,试了一下x64也可)

完成后如图:

再次编译,运行一切都正常了!

参考资料:

Building SharePoint 2010 Console Applications

原文地址:https://www.cnblogs.com/Sunmoonfire/p/1729819.html