Showing posts with label lists. Show all posts
Showing posts with label lists. Show all posts

Wednesday, August 26, 2009

Deleting an item from sharepoint list

If you would like to delete an item from SPListItemCollection in share point,
Use the following code


SPSite site = null;
SPWeb web = null;

try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
site = SPContext.Current.Site;
site.AllowUnsafeUpdates = true;
web = site.OpenWeb();
SPList list = web.Lists["Test"];
SPQuery oQuery = new SPQuery();
oQuery.Query = "" + txtGaugeID.Text + "";
SPListItemCollection oDeleteCollection = list.GetItems(oQuery);
if (oDeleteCollection.Count > 0)
{

for (int i = oDeleteCollection.Count - 1; i > -1; i--)
{
oDeleteCollection.Delete(i);
}
}
});

}
catch (Exception ex)
{
Response.Write(ex.Message);
}

Monday, July 27, 2009

Blocking anonymous users from sharepoint lists

To block the anonymous users from viewing the sharepoint lists add the following code in your web.config file

[CODE][location path="lists"]
[system.web]
[authorization]
[deny users="?"]
[/authorization]
[/SYSTEM.WEB]
[/location][/CODE}