您的位置:首页 > 其它

Manage ListItem attachment,include add attachment in listitem,list all attachments.(给ListItem增加附件)

2008-09-16 20:48 766 查看
#region add a attachment into listitem.
/// <summary>
/// Author:李曦光(Bruce Lee)
/// Created Time:2008-9-16
/// Description:add a attachment into listitem.
/// Mender:
/// Modify Time:
/// Modify Description:
/// </summary>
/// <param name="spWeb">a SPWeb object</param>
/// <param name="spListItem">SPList name</param>
/// <param name="intSPListItemId">SPListItem id</param>
/// <param name="strAttachmentName">save attachment name</param>
/// <param name="byteContent">byte attachment</param>
/// <returns></returns>
public bool AddAttachmentsInListItem(SPWeb spWeb, string strSPListName, int intSPListItemId, string strAttachmentName, byte[] byteContent)
{
bool boolReturn = false;
try
{
SPList spList = spWeb.Lists[strSPListName];
SPListItem spListItem = spList.GetItemById(intSPListItemId);
if (spListItem.Attachments != null)
{
spListItem.Attachments.Add(strAttachmentName, byteContent);
spListItem.Update();
boolReturn = true;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
spWeb.Dispose();
}
return boolReturn;
}
#endregion
#region get attachments in listitem.
/// <summary>
/// Author:李曦光(Bruce Lee)
/// Created Time:2008-9-16
/// Description:get attachments in listitem.
/// Mender:
/// Modify Time:
/// Modify Description:
/// </summary>
/// <param name="spWeb">a SPWeb object</param>
/// <param name="spListItem">SPList name</param>
/// <param name="intSPListItemId">SPListItem id</param>
/// <returns></returns>
public SPAttachmentCollection GetAttachmentsInListItem(SPWeb spWeb, string strSPListName, int intSPListItemId)
{
SPAttachmentCollection attach = null;
try
{
SPList spList = spWeb.Lists[strSPListName];
SPListItem spListItem = spList.GetItemById(intSPListItemId);
if (spListItem.Attachments != null)
{
attach = spListItem.Attachments;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
spWeb.Dispose();
}
return attach;
}
#endregion
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐