| -- |
{
int listItemId = -1;
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate()
{
if (oSite.WebApplication.ContentDatabases.Count > 0)
{
//Get the connection string for the sharepoint database
string connString = oSite.WebApplication.ContentDatabases[0].DatabaseConnectionString;
//Establish a connection
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(connString);
try
{
con.Open();
//Query to get the next item id for a list(Filtering the list by the list id)
System.Data.SqlClient.SqlCommand com = con.CreateCommand();
com.CommandText = String.Format("select tp_NextAvailableId from AllLists where tp_ID = '{0}'", listId.ToString());
listItemId = (int)com.ExecuteScalar();
}
finally
{
con.Close();
}
}
});
return listItemId;
}
浙公网安备 33010602011771号