I am working on Sharepoint and I am trying to save all the users from Active Directory into the Sharepoint under same group. If I run my code then I get this error:
The Web application at
http://localhost/
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.
string groupname = txtgroupname.Text;
Uri sitePath = new Uri(@"http://localhost");
List<ADUserDetail> users = new List<ADUserDetail>();
users = BuildList(users, "LDAP://server-abc/dc=abc,dc=bb,dc=ca", groupname);
foreach (var adUser in users)
{
using (SPSite spSite = new SPSite(sitePath.ToString()))
{
using (SPWeb spWeb = spSite.OpenWeb())
{
spWeb.AllowUnsafeUpdates = true;
SPUser spUser = spWeb.EnsureUser(adUser.Samaccountname);
if (spUser != null)
{
SPGroup spGroup = spWeb.SiteGroups[groupname];
if (spGroup != null)
spGroup.AddUser(spUser);
}
}
}
}
Dot Net version 4
Server is 64 bit (Any CPU)