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
/// <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
相关文章推荐
- 【原创】在DataFormWebPart中将列表附件显示为图片(二)[How to display list item attachments as image in DFWP Part 2]
- How to modify non-customizable entity in MS Dynamics CRM 4.0 (Add Product price column to Price List Item view)
- How to add icon for the item of ListCtrl using C++ (Mail Attachment ListCtrl) - 如何用C++为ListCtrl的Item添加图标(邮件附件ListCtrl)
- Find All Anagrams in a String Add to List
- python django1.10解决view must be a callable list/tuple in case of include()
- List All Of The Subset In Another Method
- Adding Custom Actions to the List Item Menu in SharePoint 2010 Using SharePoint Designer 2010[Sharepoint中添加自定义菜单]
- How to add a menuitem in Nautilus context menu.
- MySQL 表分区 A PRIMARY KEY must include all columns in the table's partitioning function
- add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.(转载)
- How to add a new "CustomAction" in ECB for a specific list
- TypeError: view must be a callable or a list/tuple in the case of include().解决办法
- Customization of SharePoint list menu item – Part 1 add Custom Action Item
- How to Get All Product Images in products list page?
- [转]How can I list all foreign keys referencing a given table in SQL Server?
- Mybatis 传入List类型参数,报错:There is no getter for property named '__frch_item_0' in
- Creating List Item in Oracle D2k
- mybatis 批量增加 Parameter '__frch_item_0' not found. Available parameters are [list]
- Creating a radio button item renderer on a Spark List control in Flex 4
- sqlalchemy flask-sqlalchemy. session.增加多个项目,用add_all