Question

I have googled it but am unable to find the correct answer to this problem. Below is my code that I used in my development server. Please tell me the exact solution related to that problem:

The Web application at [URL] 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.

using (SPSite _Site = new SPSite("http://demo2010a:8082/sites/Test2"))
{
    using (SPWeb _Web = _Site.OpenWeb())
    {
        foreach (SPList list in _Web.Lists)
        {
            if (count <= 4)
            {
                string listLink = "<a  href='" + list.DefaultView.Url.ToString() + "'>" + list.Title + "</a>(<b>" + list.Items.Count + "</b>)<br>";
                linksHtml += listLink;
            }
            count++;
        }

    }
}
Was it helpful?

Solution

Do you build against x64 and against the 3.5 framework?

Regards,

Kjetil Hovding Crayon, Oslo

OTHER TIPS

I was stung by the same problem and found it to be the Build option, Platform Target in my VS project Properites was set to x86. Changed to Any CPU or x64 to solve the problem.

How is your code executed? Webpart? Feature? CLI?

Is there some other way to open the site collection, such as Context?

If not, have you tried opening the root site collection first, and then try your Test2 site collection?

please check the alternate access mappings in cenztral administration. The URL must be configured. Maybe your created the application with host header and the AAM is not what your are using in your code. If you confired the iis site manualy sharepoint "may" seem to work correct, but unless AAM is configured it is only working somehow :-)

SO check your AAM and see if http://demo2010a:8082 is there. FQDN is something different... etc. It must match. No SSL, etc. Exact match :-)

Using the object model seems to use the URL to access it via HTTP, but all it does is making a SQL query to the database to see if the HOST part of your URL is a valid AAM entry.

Ciao Marco

AAM Link: http://<>/_admin/AlternateUrlCollections.aspx

PowerSHell test code: [System.reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) $site = new-object Microsoft.SharePoint.SPSite("http://demo2010a:8082/sites/Test2")

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top