Does anyone know why properties.ListItem is NULL in ItemAdded Event Handler when i add a document in Windows Explorer
Bloqueado
-
Wednesday, April 30, 2008 1:30 AM
hey everyone,
When i upload a document in a document library normally, then when i run the ItemAdded Event Handler:
public override void ItemAdded(SPItemEventProperties properties)
And then when I debug my code, properties.ListItem has a value. But when i add documents in Windows Explorer, properties.ListItem was NULL when i debuged it in Visual Studio.
does anyone know why properties.ListItem is NULL when i copy and paste existing document in windows Explorer View?
All Replies
-
Monday, May 05, 2008 4:02 PM
This is a known issue. No ETA on a fix yet.
You should be able to work around it by using the ListItemId and spList.GetItemByUniqueId.
- Unmarked As Answer by Mike Walsh FIN Thursday, July 28, 2011 7:33 AM
-
Monday, September 29, 2008 5:57 PMI've been having the same problem!
I tried with SPList.GetItemById(properties.ListItemId) and that doesn't work either, ListItemId is 0...
The GetItemByUniqueId requires the GUID of the item.... but where would I get the item GUID?
Thanks
Yohan
-
Thursday, October 09, 2008 5:49 PM
Well, i've been having the same problem but finally, i found a workaround :)
Actually, the problem can be found when the user tries to do one of the following...- Copying and pasting existing document in SharePoint windows explorer.
- Creating new folder in SharePoint windows explorer.
- Copying a folder from the pc to the SharePoint using the SharePoint windows explorer.
SPSite CurrentSite = new SPSite(properties.SiteId);
SPWeb CurrentWeb = CurrentSite.OpenWeb(properties.RelativeWebUrl);
SPList CurrentList = CurrentWeb.Lists[properties.ListId];
SPListItem CurrentListItem;
CurrentListItem = CurrentList.Items[CurrentList.Items.Count - 1]; // the added file is the last item in items collection
To solve the problem of the second and the third case
CurrentListItem = CurrentList.Folders[CurrentList.Folders.Count - 1]; // the added folder is the last item in folders collection
hope this helps :)Ahmed Amin
- Proposed As Answer by Dimitri.Dhuyvetter Wednesday, November 11, 2009 5:06 PM
- Marked As Answer by Mike Walsh FIN Thursday, July 28, 2011 7:32 AM
-
Friday, October 17, 2008 2:28 AMHi Ahmed!
Thanks for the suggestion! Funny thing is, I had found the exact same workaround! Forgot to post it so thanks!!
Indeed, hope this helps more than a few people. ;)
Yohan
-
Wednesday, December 03, 2008 5:51 AMHi Ahmed,
But in the method public override void ItemAdded(SPItemEventProperties properties), how can I know which code snip below should be used.
Users may copy/ paste a folder or a file.
CurrentListItem = CurrentList.Items[CurrentList.Items.Count - 1]; // the added file is the last item in items collection
CurrentListItem = CurrentList.Folders[CurrentList.Folders.Count - 1]; // the added folder is the last item in folders collection -
Wednesday, December 03, 2008 10:27 AM
Hi Alanzhoupsd,
You can use the following code:-
CurrentListItem = CurrentList.Items[CurrentList.Items.Count - 1];
if(properties.AfterUrl != CurrentListItem.Url)
{
CurrentListItem = CurrentList.Folders[CurrentList.Folders.Count - 1];
}
Eventually, we have found another way to get the items and it's much better.
if (CurrentWeb.GetFile(properties.AfterUrl).Exists)
{
CurrentListItem = CurrentWeb.GetFile(properties.AfterUrl).Item;
}
else if (CurrentWeb.GetFolder(properties.AfterUrl).Exists)
{
CurrentListItem = CurrentWeb.GetFolder(properties.AfterUrl).Item;
}
GoodLuck :)
Ahmed Amin- Proposed As Answer by Dimitri.Dhuyvetter Wednesday, November 11, 2009 5:07 PM
- Marked As Answer by Mike Walsh FIN Thursday, July 28, 2011 7:32 AM

