webber77
Novice

Adding Attachment to Sharepoint TaskList

Hi,

Could you please advise me on following issue:
I'm trying to create a new item in SharePoint TaskList using K2 event SharePoint TaskList, wizard loads fine and let me to enter item's name, begin & end periods, some other fields BUT it does not allow me to attach file(s).
Did I miss something or is there any other way to attach files to the Sharepoint lists?

Regards
0 Kudos
Reply
2 Replies
ConradK2
Novice

Re: Adding Attachment to Sharepoint TaskList

Hi!

Out of the box the the K2.net SharePoint List event does not allow you to add an attachment to a list. The reason for this is that the SharePoint API used by the event does not allow the attachment. From within SharePoint a different API is used to attach the document.

A workaround that would be to upload the document to a SharePoint document library using the normal K2.net SharePoint Document event template (or the Multiple document event template - Whatever suits you better) Then create your list with a link to the document.
0 Kudos
Reply
elizas1
Novice

Re: Adding Attachment to Sharepoint TaskList












A list item in SharePoint can have multiple attachments.  Below is a code snippet in c#.Net to add an attachment to a list item programmatically.



This example demonstrates how a file, uploaded through a file upload control is added as an attachment to a list item.


using (SPSite oSPsite = new SPSite(http://website Url/))



{

     using (SPWeb oSPWeb = oSPsite.OpenWeb())

      {

           oSPWeb.AllowUnsafeUpdates = true;

 

            // Fetch the List

            SPList list = oSPWeb.Lists["MyList"];

 

            // Get the List item

            SPListItem listItem = list.GetItemById(1);

           

            // Get the Attachment collection

            SPAttachmentCollection attachmentCollection = listItem.Attachments;

 

            Stream attachmentStream;

            Byte[] attachmentContent;







0 Kudos
Reply