Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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++;
        }

    }
}
share|improve this question
add comment

4 Answers 4

up vote 2 down vote accepted

Do you build against x64 and against the 3.5 framework?

Regards,

Kjetil Hovding Crayon, Oslo

share|improve this answer
    
I do not know about X64. But yes i am using 3.5 framwork. –  Basant B. Pandey Jun 14 '10 at 11:28
1  
Make sure that your build target is x64 or any CPU –  Wictor Wilen MCA MCM MVP Jun 14 '10 at 12:12
add comment

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.

share|improve this answer
add comment

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?

share|improve this answer
    
I am geeting same error. while opning site from root site collection –  Basant B. Pandey Jun 14 '10 at 12:11
add comment

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")

share|improve this answer
    
I have set the cenztral administration Following settings. Internal URL Zone Public URL for Zone demo2010a:8082 Default demo2010a:8082 Please let me know it correct... –  Basant B. Pandey Jun 15 '10 at 7:09
    
I have added a powershell sample you can try. Did you add the urls or did they allready exist? –  Marco Scheel Jun 15 '10 at 7:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.