We have a mixed (forms and Windows)-based SharePoint 2010 site and I'm attempting to use the object model in c# (command line console app, referenced to Microsoft.SharePoint, Solution Platform target is x64 [in VS 2012 I had to create a new solution platform, settings copied from <Empty>].)

In PowerShell, I can simply do something like

$site = Get-SPSite http://www.server.com/sites/site1

It successfully retrieves the object, and I can open the contained SPWebs, etc. as I please. However, when I attempt similar logic in C# (on the same box under the same user credentials) like

using(SPSite site = new SPSite("http://www.server.com/sites/site1") { }

it fails with the FileNotFoundException. Any attempts to use the associated Guids follow the same issue. Why might this be happening?

Also, I am an administrator on the box and also explicitly have sysadmin server role on the database.

有帮助吗?

解决方案 2

For anyone experiencing this as well. PowerShell 3 does not support SharePoint methods. I discovered after installing Powershell v3 that I had to enter another shell using the command powershell -version 2 first before running SharePoint commands, which led me to realize that my VS project was targeting .NET 4.5; Once I changed it to .NET 3.5, everything worked.

I assume that despite the SharePoint libraries targeting .NET 3.5, and theoretically the .NET 4 CLR can handle .NET 2 CLR libraries, Projects with usage of SharePoint 2010 do not support targeting .NET 4/4.5 in any way.

Happy to be proved wrong, of course ;)

其他提示

I assume you are doing this in a command prompt? If so, please make sure you are compiling your project in x64. This is the error message I see when I compile my code in x86 or Any CPU.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top