.net 带有 SPSite 构造函数的 FileNotFoundException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/266255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FileNotFoundException with the SPSite constructor
提问by Maxime Rouiller
I try to instantiate an instance of SPSiteon the farm server in a custom process (MyApp.exe) and I give it as parameter the whole URI (http://mysite:80/). I also made sure that the account running MyApp.exeis Site Collection Administrator.
我尝试SPSite在自定义进程 (MyApp.exe) 中实例化场服务器上的一个实例,并将整个 URI ( http://mysite:80/)作为参数提供给它。我还确保运行的帐户MyApp.exe是Site Collection Administrator.
However, I can't make an instance of SPSitewhatever I am trying to do. It always throws a FileNotFoundException.
但是,我无法举例说明SPSite我正在尝试做的任何事情。它总是抛出一个FileNotFoundException.
Anyone got an idea?
有人有想法吗?
StackTrace:
堆栈跟踪:
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl) at MyCompanyName.Service.HelperClass.GetItemStateInSharePoint(SharePointItem item) in C:\Workspaces\MyCompanyName\Development\Main\MyCompanyName.SharePoint\Service\HelperClass.cs:line 555
在 Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
在 Microsoft.SharePoint.SPSite..ctor(String requestUrl) 在 MyCompanyName.Service.HelperClass.GetItemStateInSharePoint(SharePointItem item) 在 C: \Workspaces\MyCompanyName\Development\Main\MyCompanyName.SharePoint\Service\HelperClass.cs:line 555
Another side note... I have a Web Application + Site collection that I can access through the browser without any problem.
另一个注意事项...我有一个 Web 应用程序 + 网站集,我可以通过浏览器访问它,没有任何问题。
采纳答案by Lars Fastrup
The FileNotFoundException is thrown by SharePoint when it cannot find the requested site collection in the SharePoint configuration database. My guess is that you have not yet created a site collection on the URL http://mysite:80. I see the following stack trace if I try and instantiate a new SPSite object with the URL of a non-existing site collection:
当 SharePoint 无法在 SharePoint 配置数据库中找到请求的网站集时,SharePoint 将引发 FileNotFoundException。我的猜测是您尚未在 URL http://mysite:80上创建网站集。如果我尝试使用不存在的网站集的 URL 实例化一个新的 SPSite 对象,我会看到以下堆栈跟踪:
System.IO.FileNotFoundException : The site http://server/sites/bah could not be found in the Web application SPWebApplication
Name=SharePoint - 80 Parent=SPWebService.
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
Specify the proper URL of your site collection or open Central Administration and create a new Site Collection.
指定网站集的正确 URL 或打开管理中心并创建新的网站集。
回答by Charles Chen
Changing the platform target in the build properties to x64 solved this issue for me on SharePoint 2010.
将构建属性中的平台目标更改为 x64 为我在 SharePoint 2010 上解决了这个问题。
回答by Olof Szymczak
Read this site http://community.bamboosolutions.com/forums/t/8179.aspxif you are running your OS x64 bit and are using MSTest (32bit) it will fail, use nunit works!!!
阅读此站点http://community.bamboosolutions.com/forums/t/8179.aspx如果您运行的是 x64 位操作系统并且使用的是 MSTest(32 位),它将失败,使用 nunit 可以工作!!!
回答by user379310
This Issue is more of user permission issue give the following permission
此问题更多是用户权限问题,请授予以下权限
User Permission SharePoint Site--- Minimum Read Permission
用户权限 SharePoint 站点--- 最低读取权限
Sharepoint Server--- Add to WSS_ADMIN_WPG group
Sharepoint 服务器--- 添加到 WSS_ADMIN_WPG 组
Database--- Sharepoint Content DB (Site collection database) - db_owner permission Sharepoint Config DB (Config DB of sharepoint installation) - - db_owner permission
Database--- Sharepoint Content DB(网站集数据库)- db_owner 权限 Sharepoint Config DB(sharepoint 安装的Config DB)- - db_owner 权限
Read more in my blog
在我的博客中阅读更多
http://sharepointinstallation.blogspot.com/2010/12/minimal-permission-required-to-execute.html
http://sharepointinstallation.blogspot.com/2010/12/minimal-permission-required-to-execute.html
回答by Lester
If it is a console application accessing SharePoint 2010 you make sure your project's Build Target is x64 and the .NET Framework is 3.5.
如果它是访问 SharePoint 2010 的控制台应用程序,请确保项目的构建目标为 x64,并且 .NET Framework 为 3.5。
回答by Abs
It's also possible that the object model doesn't like the URL you're giving it. If you don't provide it with either the exact URL at which you created the site collection or an exact URL listed in your is configured in your Alternate Access Mappings, it will throw an exception that might not necessarily make sense. In your case you might try http://mysiteor http://machinename.
对象模型也可能不喜欢您提供的 URL。如果您没有向它提供创建网站集的确切 URL 或在您的备用访问映射中配置的确切 URL,它将抛出一个可能不一定有意义的异常。在您的情况下,您可以尝试http://mysite或http://machinename。
回答by axk
I have recently discovered that this problem with the constructor can be cause by starnge behaviour of the constructor.
I'm taking about MOSS 2007.
When you're passing a full site URL to the constructor, what it seems to do is to really consider only the site portion of the URL, choosing the web application which is 'currently seleced' in the web application selector control.
Thus, for example, when you have "http://webapp/sites/site" and have "http://weabapp:22345" currently selected (the last time you selected it in such a selector) when you call
我最近发现构造函数的这个问题可能是由构造函数的异常行为引起的。
我正在考虑 MOSS 2007。当您将完整的站点 URL 传递给构造函数时,它似乎只真正考虑 URL 的站点部分,选择“当前选择”的 Web 应用程序Web 应用程序选择器控件。
因此,例如,当您有“ http://webapp/sites/site”并且当前选择了“ http://weabapp:22345”(您最后一次在此类选择器中选择它时),当您调用
SPSite site = new SPSite("http://webapp/sites/site")
It tries to actually create a site object for "http://webapp:22345/sites/site" and fails.
它尝试为“ http://webapp:22345/sites/site”实际创建站点对象并失败。
回答by axk
Stacktrace of the exception would be helpful.
异常的堆栈跟踪会有所帮助。
I think you possibly can get some idea of what file it is and what is happening by disabling "just my code" in tools -> options -> debugging and looking at the filename argument in the call stack of the exception when the debugger shows it (if you can debug it of course), or maybe the name shows up in the exception message.
我认为您可以通过在工具 -> 选项 -> 调试中禁用“仅我的代码”并在调试器显示异常的调用堆栈中查看文件名参数来了解它是什么文件以及正在发生的事情(当然,如果您可以调试它),或者该名称可能会显示在异常消息中。
回答by vIceBerg
Check your web.config and see if there's a config there with a file missing.
检查您的 web.config 并查看那里是否存在缺少文件的配置。
Look in you 12 hive for the log. If your log settings are correct, you'll get the file missing.
在你的 12 hive 中查看日志。如果您的日志设置正确,您将丢失该文件。
EDIT: Check also if ALL your DLL are in the GAC. Check if your web.config file contains all the information: namespace,Classname, NameSpace, Version=version_number, Culture-your_culture, PublicKeyToken=your_signed_token
编辑:还要检查您的所有 DLL 是否都在 GAC 中。检查您的 web.config 文件是否包含所有信息:namespace、Classname、NameSpace、Version=version_number、Culture-your_culture、PublicKeyToken=your_signed_token
回答by vibloggers
I had the same issue. I wanted to run console application with my user id. I am web application owner + Farm Admin. Still was not able to run the application.
我遇到过同样的问题。我想用我的用户 ID 运行控制台应用程序。我是网络应用程序所有者 + 农场管理员。仍然无法运行该应用程序。
Issue was resolved by
问题已解决
Changing the platform target in build properties to x64
In site settings -->Users and Permissions --> Site Collection Administrators there were two names. Removed other name and it started working.
将构建属性中的平台目标更改为 x64
在站点设置 --> 用户和权限 --> 站点集管理员中有两个名称。删除其他名称并开始工作。

