1

I have a shopping cart like application running on SharePoint 2007.

I'm running a very standard update procedure on a list item:

            using (SPWeb web = site.OpenWeb())
            {
                web.AllowUnsafeUpdates = true;
                SPList list = web.Lists["Quotes"];
                SPListItem item = list.GetItemById(_id);
                item["Title"] = _quotename;
                item["RecipientName"] = _quotename;
                item["RecipientEmail"] = recipientemail;
                item["IsActive"] = true;
                item.Update();
                site.Dispose();
            }

This item updates properly, however it briefly appears as modified by System Account. If I wait a second and refresh the page, it shows up again as modified by CurrentUser.

This is an issue because on Page_Load I am retrieving the item that is marked as Active AND is listed as Modified By the CurrentUser. This means as a user updates his list, when the PostBack finishes, it shows he has no active items.

Is it the web.AllowUnsafeUpdates? This is necessary because I was getting a security error before.

What am I missing?

Wesley
  • 5,381
  • 9
  • 42
  • 65
  • 1
    off topic: your use of AllowUnsafeUpdate is wrong. If you need it (but here you don't need it probably), you have to call `.Update()` on the SPWeb object to apply the property. You also have to restore the value after your code. Check [my blog entry](http://blog.hand-net.com/sharepoint/2010-07-26-sharepoint-allowunsafeupdate-simplifie.htm) to see a wrapper that simplify this operation. – Steve B Jun 11 '12 at 07:34

2 Answers2

1

First off, it's not AllowUnsafeUpdates. This simply allows modifying of items from your code.

It's a bit hard to tell what's going on without understanding more of the flow of your application. I would suggest though that using Modified By to associate an item to a user may not be a great idea. This means, as you have discovered, that any modification by the system or even potentially an administrator will break that link.

I would store the current user in a custom field. That should solve your problem and would be a safer design choice.

Nigel Whatling
  • 2,371
  • 1
  • 16
  • 22
0

There could be some other code running in Event Receivers and updating the item. Because event recievers runs in context of system user account, and if you update item from event reciever, the modified field will show just that: the system account has modified the item.

Janis Veinbergs
  • 6,907
  • 5
  • 48
  • 78