title: Sharepoint 2010 Event Receiver just works in Administrator account
body: <p>I have an event receiver that creates 13 subfolders automatically when a folder is created by user. The code below can do this and everything is ok when the Administrator account creates the folder. But when it comes to other users, the subfolders are not created whitout any error.</p>
  
  <pre><code>public override void ItemAdded(SPItemEventProperties properties)
  {
      base.ItemAdded(properties);
      SPWeb web = properties.OpenWeb();
      web.AllowUnsafeUpdates = true;
      SPDocumentLibrary docLib = (SPDocumentLibrary)web.List[properties.ListId];
      if (properties.ListItem.ContentType.Name == "Folder"
          &amp;&amp; properties.ListItem.Folder.ParentFolder.ToString().ToLower().EndsWith("opportunity"))
      {
          String url = properties.ListItem.ParentList.RootFolder.ServerRelativeUrl.ToString();
          SPFolder libFolder = properties.ListItem.Folder;
          string newFolderUrl = (web.Url + "/" + libFolder.ToString());
          foreach (string subfolder in folders)
          {
              SPListItem newFolder = docLib.Items.Add(newFolderUrl, SPFileSystemObjectType.Folder, subfolder);
              newFolder.Update();
          }
      }
  }
  </code></pre>
  
  <p>I read many posts about elevating SPSite and SPWeb and wrote a code to elevate the objects before I create subfolders. However the code below doesn't work:</p>
  
  <pre><code>public override void ItemAdded(SPItemEventProperties properties)
  {
      Guid siteId = properties.SiteId;
      Guid webId = properties.OpenWeb().ID;
      SPSecurity.RunWithElevatedPrivileges(delegate()
      {
          using (SPSite elevatedSite = new SPSite(siteId))
          {
              using (SPWeb web = elevatedSite.OpenWeb(webId))
              {
                  base.ItemAdded(properties);
                  web.AllowUnsafeUpdates = true;
                  SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[properties.ListId];
                  if (properties.ListItem.ContentType.Name == "Folder"
                       &amp;&amp; properties.ListItem.Folder.ParentFolder.ToString().ToLower().EndsWith("opportunity"))
                  {
                      String url = properties.ListItem.ParentList.RootFolder.ServerRelativeUrl.ToString();
                      SPFolder libFolder = docLib.RootFolder.SubFolders[properties.ListItem.Name];
                      SPFolder libFolder = properties.ListItem.Folder;
  
                      string newFolderUrl = (web.Url + "/" + libFolder.ToString());
                      foreach (string subfolder in folders)
                      {
                          SPListItem newFolder = docLib.Items.Add(newFolderUrl, SPFileSystemObjectType.Folder, subfolder);
                          newFolder.Update();
                      }
                }
                web.AllowUnsafeUpdates = false;
              }
           }
      });
  } 
  </code></pre>
  
  <p>Can anybody help to solve the problem?
  Note that all the users are home members and can create folders manually.</p>