Showing posts with label Error And Solutions. Show all posts
Showing posts with label Error And Solutions. Show all posts

Thursday, June 30, 2016

For each loop processes half of the items in K2 workflow.


Scenario 
In my scenario, I have SharePoint list hooked up with smartobject. SharePoint list has flag column (Yes/No), default is set to No. All the items are set to No at the beginning. 

For each loop is set to retrieve 1 item at a time. Then it is doing some operations on that item. Then finally, I am setting flag column to Yes, indicating that item has been processed.


Issue
After updating the flag to Yes, next, loop is retrieving only odd number item from a list, and skipping even number items (basically, it is processing only half of times in the list or only alternate items).

Without update operation, it works fine.

Workaround

Decreasing the index of the for-each loop after the for-each event loop processes all the items.


Friday, November 2, 2012

The Web Application Could Not Found

Scenario: I wrote very much simple code as shown below in Web application on button click.

(SPSite site = new Microsoft.SharePoint.SPSite("http://yadnesh-pc/sites/MyTestBed/"))
{
using (SPWeb web = site.OpenWeb())
{
// get wikipagelibrary and file
SPListCollection listCollection = web.Lists;
SPList WikiList = listCollection["WkiPageLibrary"];
SPFile Wikifile = WikiList.Items[0].File;
}
}


but when I debugged the code I was getting following error at (SPSite site = new Microsoft.SharePoint.SPSite(
http://yadnesh-pc/sites/MyTestBed/)) this line.The Web application at http://yadnesh-pc/sites/MyTestBed/ could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
Solution:
I write the code in console application i was getting the same error after doing some Google, I changed project properties as follow
Right click on project-> properties -> build -> platform target -> set it to "any CPU" or "x64".
then error gone.
But same I did for web application but no luck....

Monday, August 15, 2011

Trying to use an SPWeb object that has been closed or disposed and is no longer valid.


Scenario:

For the following code i was getting following error at the closing bracket of "ImageButton1_Click" methode below is code.

Error :Trying to use an SPWeb object that has been closed or disposed and is no longer valid.

 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            using (SPSite site =SPContext.Current.Site )
            {
                using (SPWeb web = site.OpenWeb())
                {
                    // get wikipagelibrary and file
                    int count = 0;
                    SPList WikiList = web.Lists["WikiPageLibrary"];
                    if( int.Parse(WikiList.Items[0]["LikeCount"].ToString())!=null)
                    count = int.Parse(WikiList.Items[0]["LikeCount"].ToString()) + 1;
                    SPListItem item = WikiList.Items[0];
                    item["LikeCount"] = count;
                    item.Update();
                    web.AllowUnsafeUpdates = false;
                }
            }
        }
Solution:

Then I changed the code  using (SPSite site =SPContext.Current.Site ) to
using (SPSite site =new SPSite (SPContext.Current.Site.Url)) and error gone;