Thursday, September 25, 2014

SharePoint error: Web application at "http://xyz" could not be found

Solutions: 
1) I had to add myself to the WSS_ADMIN_WPG group on the server. Hope this helps someone.
2)  If  user's account is already a member of WSS_ADMIN_WPG and issue still not  resolved
Try the following steps. :
 Go to Project Properties ---> Build Tab ---> Change the Platform Target value to "Any CPU" from the Drop Down Available.
3) If the Problem still persist and you are able to run the code in Dev environment and problem with other Environments(Like QA,Prod) then run the code with "RunWithElevatedPrevileges" objectmodel Like below code 

"Guid siteId = SPContext.Current.Site.ID;

Guid webId = SPContext.Current.Web.ID;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(siteId))
    {
        using (SPWeb web = site.OpenWeb(webId))
        {
            // Your code here
        }
    } 
});"
4)The other option is write client Object Model

string siteUrl = "http://dev.rainerj.local/sites/ee"; ClientContext clientContext = new ClientContext(siteUrl); Microsoft.SharePoint.Client.List spList = 
clientContext.Web.Lists.GetByTitle("EEReportStatus"); ListItemCreationInformation newItemInfo = 
new ListItemCreationInformation(); ListItem spListItem = spList.AddItem(newItemInfo); spListItem["Title"] = "Test from COM"; spListItem["Status"] = "Completed"; spListItem["Sector"] = "Industry"; spListItem.Update(); clientContext.ExecuteQuery();


To run the above code you have to add two references to your VS project:

1) Microsoft.SharePoint.Client.dll 
2) Microsoft.SharePoint.Client.Runtime.dll