Welcome to K2 Underground Sign In | Join | Help
One way to retrieve Sharepoint List Attachments through a SmartObject

There are K2 Service Object types for a multitude of resources.  Recently a dynamic web service ServiceObject has been published in beta form that allows K2 to enumerate and access simple web services through SmartObjects.  This document covers setting up a custom web service that provides access to Sharepoint List Attachments for the Dynamic Web Service SmartObject Service to consume.

You will need to download and setup the Dynamic Web Service SmartObject Service available on BlackMarket in order to make use of the web service covered in this document.

This project is limited to one-dimensional arrays of data being returned, but this code could be adapted to return an xml string instead to provide access to record data.

The step by step instructions were developed and tested on the base Training VPC and include instructions for IIS configuration in addition to all code required to create the simple web service.

This code is featured within the attached document, as you can see it isn't hard to write a simple web service:

        public String[] ListAttachments(string strListName, string strListItemID)
        {
            SPWeb spWeb = null;
            SPList spList = null;
            SPListItem spListItem = null;
            int nListItemID = 0;
            int nRowValue = 0;
            String[] strFiles = null;

            //cast the incoming ID to int
            nListItemID = Convert.ToInt32(strListItemID);

            try
            {
                //define the Overall Sharepoint Site URL and the "web" within (often blank)
                //Customize the MOSS Site URL if necessary in the web.config <appSettings> section
                SPSite spSite = new SPSite(System.Configuration.ConfigurationManager.AppSettings["MossServerURL"]);
                spWeb = spSite.OpenWeb();

                if (spWeb != null)
                {
                    //open the sharepoint list
                    spList = spWeb.Lists[strListName];

                    //open the list item
                    spListItem = spList.GetItemById(nListItemID);

                    //populate each attachment into the strFiles array
                    strFiles = new String[spListItem.Attachments.Count];
                    foreach (string strAttachment in spListItem.Attachments)
                    {
                        strFiles[nRowValue] = spListItem.Attachments.UrlPrefix + strAttachment;
                        nRowValue += 1;
                    }
                }               
            }
            catch
            {
                //if the Sharepoint site, List or Attachments cannot be found, empty string array
                strFiles = new String[0];
            }
            return strFiles;
        }

Published Wednesday, May 21, 2008 3:58 PM by Joseph


Attachment(s): List Attachments from Sharepoint with a Simple Custom Web Service.doc

Comments

No Comments

Anonymous comments are disabled
Powered by Community Server (Commercial Edition), by Telligent Systems