/// <summary>
/// Get the next available item id from a list
/// </summary>
/// < param name="site">site</param>
/// < param name="listId">listId</param>
/// < returns></returns>
public static int NextItemID(SPSite site, Guid listId(
}
int id = -1;
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate()
}
if (site.WebApplication.ContentDatabases.Count >
0(
{
string DBConnString =
site.WebApplication.ContentDatabases[0].DatabaseConnectionString;
SqlConnection con = new
SqlConnection(DBConnString);
try
{
con.Open();
SqlCommand com = con.CreateCommand();
com.CommandText = String.Format("select
tp_NextAvailableId from AllLists where tp_ID = '{0}'", listId.ToString());
id = (int)com.ExecuteScalar();
}
finally
{
con.Close();
}
}
});
return id;
{
...
int itemId = NextItemID(new SPSite(properties.SiteId),
properties.ListId);
As you can see, the solution is to connect to the MOSS
database and read the ID AllList table. All the information was right there, we
simply had to access it.
|