w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Updating list items in a different site within the same site collection using a custom workflow activity

Thank you, Yevgeniy, for your helpful comments. I was able to find a solution using the Server object model as suggested by Yevgeniy. Thanks also to this blog post. The following code solves the problem.

using (SPSite _site = new SPSite(SiteUrl))
            {
                using (SPWeb _web = _site.OpenWeb())
                {
                    SPList oList = _web.Lists[List];
                    SPQuery _query = new SPQuery();

                    _query.Query = "<Where><Eq><FieldRef
Name='"+Column+"' /><Value
Type='Text'>"+Value+"</Value></Eq></Where>";
                    SPListItemCollection _itemCollection =
oList.GetItems(_query);

                    if (_itemCollection.Count > 0)
                    {
                        _web.AllowUnsafeUpdates = true;

                        foreach (SPListItem Item in _itemCollection)
                        {
                            Item[updateCol] = updateVal;
                            Item.Update();
                        }

                        _web.AllowUnsafeUpdates = false;
                    }
                }
            }




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.