Manage listitem attachment, include add attachment in listitem, list all attachments. (add attachments to listitem)

Source: Internet
Author: User

# Region add a attachment into listitem.
/// <Summary>
/// Author: Bruce Lee)
/// Created time:
/// 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, string strsplistname, int intsplistitemid, string strattachmentname, byte [] bytecontent)
{
Bool boolreturn = false;
Try
{
Splist = spweb. Lists [strsplistname];
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:
/// 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, string strsplistname, int intsplistitemid)
{
Spattachmentcollection attach = NULL;
Try
{
Splist = spweb. Lists [strsplistname];
Splistitem = splist. getitembyid (intsplistitemid );
If (splistitem. attachments! = NULL)
{
Attach = splistitem. attachments;
}
}
Catch (exception ex)
{
Throw ex;
}
Finally
{
Spweb. Dispose ();
}
Return attach;
}
# Endregion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.