Tuesday, June 26, 2012

Delete items from sharepoint list

In some case, you may want to delete item in sharepoint list. It is easy job.

Ex. You have a list named "Sample List"
using (SPSite siteCollection = new SPSite("http://server")) {
    using (SPWeb site = siteCollection.OpenWeb()) {
        SPList list = site.Lists["Sample List"];

        foreach (SPListItem item in list.Items) {
            item.Delete();
        }
    }
}

Weird dialog box in membership change password control

You may experience with a weird dialog box which ask you to select a user if you want to change password. This happen with mostly Firefox browser (It can be happened with other browser).

The problem is that you use remember password in the Firefox browser. I think it is the bug from Firefox itself. Nothing to do with Asp.net member ship.

To fix this problem, you go to
1- Tool
2- Option
3- Security
4- Remove All

Read item from sharepoint list

In some case, you may want to get all list item in sharepoint list. It is easy to get all those list. below are code for reading list item from sharepoint list.

Ex. You have a list named "Sample List"
using (SPSite siteCollection = new SPSite("http://server")) {
    using (SPWeb site = siteCollection.OpenWeb()) {
        SPList list = site.Lists["Sample List"];

        foreach (SPListItem item in list.Items) {
            //do what you want to do with it.
        }
    }
}
  

Fix error when create task in loop

If you create task in loop, you will got the message "Error occurred".
The problem is that you don't understand the correlation of the task.

The following is how to fix it.