new SPSite("http://site") gives System.IO.FileNotFoundException RRS feed

  • Question

  • Greetings,

    A colleague of mine has developed a functioning console application that simply performs a little search using an SPQuery object.

    I’ve created a web service to be called by BDC to do this.

    My web service code fails here:

       using (SPSite site = new SPSite("http://sharepointapp01/sandbox"))


    When I attempt to execute the method from a web browser, I get this:


    System.IO.FileNotFoundException: The Web application at http://sharepointapp01/sandbox 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 requestUri, Boolean contextSite, SPUserToken userToken)

       at Microsoft.SharePoint.SPSite..ctor(String requestUrl)

       at Conchango.xyzzyFacade.GetExistingDocument(String minId, String maxId, String titleFilter) in C:\Documents and Settings\Paul\My Documents\Visual Studio 2005\Projects\xyzzy\BDC_DocReview\BDC_DocReview\DocReviewFacade.asmx.cs:line 69


    I can access http://sharepointapp01/sandbox fine from a web browser.  SharePoint does challenge me for credentials when I log in using a web browser on the server, even though I’m obviously already successfully logged into the server itself.  Same credentials work both times, I just have to enter it again.  I don’t know if that’s the problem.


    I’ve searched and found that a lot of people have this issue, but there are relatively few successful answers or their solutions don’t work for me.


    Again, it works fine from a console application running on the server.  However, my web service, also running on the server, generates the above error.


    Any insights greatly appreciated.




    --Paul Galvin



    Friday, February 1, 2008 12:38 AM


All replies

  • Hi Paul,


    Make sure the user account for the app pool has rights to SQL and is a member of the WSS_ADMIN_WPG group.

    Lack of permissions in either will give this error from the SPSite() constructor.



    • Proposed as answer by SPTQs Wednesday, April 24, 2013 4:52 PM
    Thursday, February 7, 2008 3:46 PM
  • Thank you for the feedback.


    I solved my problem earlier this week and blogged about it here: http://feeds.feedburner.com/~r/PaulGalvinsSharepointSpace/~3/230017467/cns!1CC1EDB3DAA9B8AA!687.entry


    We did go and give the app pool identity permission to SQL and that solved it.  Thanks for the concise statement, it's helpful.


    --Paul Galvin



    Thursday, February 7, 2008 4:05 PM
  • I had some code running in IIS under a different website than SharePoint (port 8080). I had the same "FileNotFound" exception when my code called various SharePoint API's.

    In my case:
    Right click on my site->Properties->Home Directory, change the APPLICATION POOL to the SAME pool as SharePoint solved it.

    Probably not a best practice, but another possible way to tackle this.

    Jeffrey Knight | MCTS .NET 2.0 | RHCT | http://www.rootsilver.com
    Wednesday, October 15, 2008 5:30 AM
  • Hi,

    I face the same issue but none of the solution works.  

    My program only have 1 line of code :

            private void button1_Click(object sender, EventArgs e)  
                SPSite mySite = new SPSite("http://server001");  

    I am always using the same user : dotech

    That user :
        - Has rights to access the SQL Database directly
        - Is an Administrator on the Sharepoint Server (server001)
        - Is part of the WSS_ADMIN_WPG
        - Is a Farm Administrator
        - The Application Pool (for WSS Site and Central Admin) uses that user.

    When I run my program directly on the Sharepoint server (server001) the application works fine and the SPSite is created successfully.

    When I run it remotely from any other computer (logged with my dotech user) I get the FileNotFoundException.  But I can access the WSS site (with Internet Explorer) from that computer without any problem.

    Hope someome can help me!

    Thursday, March 26, 2009 1:33 PM
  • The WSS object model does not work remotely. You'll need to use the Web Services if your code has to run off the farm.
    Posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, March 26, 2009 1:59 PM
  • For the record and for what is worth, I had a similar problemo. In my case, the Web Service is meant to process some InfoPath forms. At any rate, I solved it by changing the WebService's Application Pool (in the IIS) to match that of the SharePoint site collection.


    Fernando Gómez
    Tuesday, October 20, 2009 5:37 PM
  •  I think the user which is run the program must bu a member of WSS_ADMIN_WPG group  or WSS_WPG group
    Wednesday, October 13, 2010 7:03 PM
  • This Issue is more of user permission issue give the following permission

    User Permission SharePoint Site --- Minimum Read Permission

    Sharepoint Server --- Add to WSS_ADMIN_WPG group

    Database --- Sharepoint Content DB (Site collection database) - db_owner permission Sharepoint Config DB (Config DB of sharepoint installation) - - db_owner permission

    Read more in my blog


    Monday, December 6, 2010 5:55 PM
  •  had the same problem, I made below changes and it started working.

    1)Changing the platform target in visual studio to x64 2) make sure you are running visual studio in "Administrator" mode.

    Saturday, January 19, 2019 1:38 PM