using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Web;
namespace MyProject.Features
{
public class MyEventReceiver : SPItemEventReceiver
{
HttpContext currentContext;
public MyEventReceiver()
{
currentContext = HttpContext.Current;
}
public override void ItemAdding(SPItemEventProperties properties)
{
if (currentContext != null)
{
if (currentContext.Request.Files.Count > 0)
{
// there are attachments
}
else
{
// there are no attachments
}
}
}
}
}
我之前也以为能用item.Attachment.count去监视,后来发现这个时候都还是正在更新,并不能监视此时有没有附件。
所以用HttpContext.Current;来监视是最好的,因为它可以监视上传流。