运行 using (SPSite spsite = new SPSite("http://localhost/"))这句话后报错:
请问是怎么回事呢?
------解决思路----------------------
你创建的是什么类型的项目?
------解决思路----------------------
你是不是用SharePoint 2010 + PowerShell 3.0? 因為SP2010預設只支持PowerShell 2.0,
參考這個做法:
?Type "PowerShell -v 2" (without quotes). This loads PowerShell version 2, and you should be able to use it for SharePoint. Just type 'Exit' to get back to PowerShell v3
?Add '-version 2.0' parameter when executing PowerShell 3.0, and SharePoint integration should work.
?Change the Target field value for SharePoint 2010 Management Shell to the following:
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -Version 2.0 -NoExit " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\SharePoint.ps1 ' "