Wednesday, April 14, 2010

System.IO.FileNotFoundException on "SPSite = new SPSite(url/IP)"

The below code snippet describes the way to insert user profile data into the SharePoint user profile store. At the time of running the code i came across the above said error. I was googling nearly for 1 1/2 days to figure out the problem. I was trying so many options to solve this problem and nothing worked fine. So finally figured it out its due to some permission problem with the application pool. The application pool identity account should be a domain administrator account which has full access (in other words it should be the same identity like the identity account of the MOSS application pool). details

that account should have following permissions:

  1. The account should be a server farm administrator.
  2. The account has permissions to access the content database.
  3. The account is a site collection administrator.
  4. The account  should have permission to access the Windows SharePoint Services site or the SharePoint Server 2007 site through which the code iterates.

by the way when i was reading through some of other blogs they have mentioned its due to 32/64 bit version. i tried that solution too and it didn't work for me. you can read more about this via this link.

string strSharePointSite = @"http://NQ02WBIZWS1";
using (SPSite site = new SPSite(strSharePointSite))
    Microsoft.Office.Server.ServerContext context = ServerContext.GetContext(site);
    UserProfileManager profileManager = new UserProfileManager(context);
    UserProfile newUserprofile = null;
    string sAccount = @"domainname\username";
    if (!profileManager.UserExists(sAccount))
        UserProfile profile = profileManager.CreateUserProfile(sAccount);
        if (null == profile)
            textBox1.Text = "Failed to Create User with account :" + sAccount.ToString();
            textBox1.Text = "UserProfileHandler.CalltotheWebService ... User profile created. ...";
        textBox1.Text = "UserProfileHandler.CalltotheWebService ... User profile already exists...";
    newUserprofile = profileManager.GetUserProfile(sAccount);
    newUserprofile[PropertyConstants.Title].Value = "Mr.";
    newUserprofile[PropertyConstants.FirstName].Value = "First Name";
    newUserprofile[PropertyConstants.LastName].Value = "Last Name";
    newUserprofile[PropertyConstants.Department].Value = "IT";

please refer something about access mappings because it will help in some way.