Home » ActionScript 3.0, Flex, Sharepoint

Add attachment to SharePoint 2010 List using Flash / Flex webservice

9 March 2011 11 Comments
Share on Facebook

In Previous post guides you to add, update and delete SharePoint List Item. In this tutorial we are going to see how to add an attachment to SharePoint List item from Flash CS5 and Flex(Flash builder) using SharePoint Connector library. Before going into the tutorial, download and setup the SharePoint Connector.

Add Attachment to SharePoint List:

Make a call to addAttachment method of SharePOint Class to add an attachment to SharePoint List.

_sharepoint.addAttachment(handleUploadedResult, ListName, ID, FileName, Attachment )

Parameters:

  • handleUploadedResult: Process the response XML
  • ListName: A string that contains the ListName or the GUID of the SharePoint List
  • ID: A String that represents the ID value of SharePoint List item, This is Unique for each rown item.
  • FileName: Name of the file to be added as attachment.
  • Attachment: A byte array that contains the file to attach by using base-64 encoding.

 

 

 

 

SharePoint list attachment using Flash CS5:

The attachment that we are going to upload must be base-64 encoded.

import com.sharepoint.SharePointConnector;
import com.sharepoint.events.SharepointEvent;
import com.sharepoint.events.UploadEvent;
import com.sharepoint.services.*;
import com.Manager.UploadManager;

var _uploadManager:UploadManager;

var _sharepoint:SharePointConnector = new SharePointConnector();
_sharepoint.connect( "http://ea.sharepoint.designscripting.com/teams/CONNECTOR" );
_sharepoint.addEventListener( SharepointEvent.CONNECTED, handleConnectedEvent );

function handleConnectedEvent( e:SharepointEvent ):void
{
	trace( "Sharepoint Connected:::"+e.connected );
}

browse_mc.addEventListener( MouseEvent.CLICK, browse);
function browse(event:MouseEvent):void
{
	_uploadManager = new UploadManager();
	_uploadManager.invoke();
	_uploadManager.addEventListener( UploadEvent.UPLOADED, handleUploaded );
}

function handleUploaded(e:UploadEvent):void
{
	var _fileRef:FileReference = e.fileReference as FileReference;
	loadedFileName_txt.text = _fileRef.name;

	_sharepoint.addAttachment(handleUploadedResult, "Country", '6',_fileRef.name, e.byte )

}

function handleUploadedResult(xml:XML)
{
	trace("Response XML:"+xml)
}

Sample Response XML After adding an attachment:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <AddAttachmentResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <AddAttachmentResult>Lists/Country/Attachments/6/Flash.jpg</AddAttachmentResult>
    </AddAttachmentResponse>
  </soap:Body>
</soap:Envelope>

The response XML contains the relative path of the uploaded file “Lists/Country/Attachments/6/Flash.jpg” and the ID in the path ‘6’.

Conclusion:

SharePoint as3 Connector library saved me number of hours when working with SharePoint and Flex or Flash applications. Feel free to add comment and contribute to the libary.

You can get the latest version of the code from
http://code.google.com/p/sharepoint-as3-connector/

Download SharePoint Connector Sample Files

 

GET THE UPDATES VIA EMAIL

We don't share your email anywhere, grab our rss via feedburner


11 Comments »

  • Chris said:

    Thanks! Great work.

  • Apparaoj said:

    hi i am new to flex,ncan you provide me complete code for attachment?

  • Anonymous said:

    Hi,nnYou can directly download the samples file from google codennhttp://code.google.com/p/sharepoint-as3-connector/nnCode is in AS3 works well in Flex too..nnRegardsnSaravanannhttp://www.designscripting.com/nhttp://www.mp3cutter.in/

  • Apparaoj said:

    hi i am unable to open .fla files, can you provide me .txt file(source code)

  • Anonymous said:

    Tutorial on Sharepoint attachment http://www.designscripting.com/2011/03/add-attachment-to-sharepoint-2010-list-using-flash-flex-webservice/ nDownload Class files http://code.google.com/p/sharepoint-as3-connector/downloads/listnnDont forget to add base-64 swc file to project which is available in bin nCode from UploadDocumentSharePoint.fla ————————————————n/*nFlash SharePoint Connector tutorial bynnhttp://www.designscripting.comnn*/nnimport com.sharepoint.SharePointConnector;nimport com.sharepoint.events.SharepointEvent;nimport com.sharepoint.events.UploadEvent;nimport com.sharepoint.services.*;nimport com.Manager.UploadManager;nnvar _uploadManager:UploadManager;nnvar _sharepoint:SharePointConnector = new SharePointConnector(); _sharepoint.connect( ” http://ea.sharepoint.designscripting.com/teams/CONNECTOR” ); _sharepoint.addEventListener( SharepointEvent.CONNECTED, handleConnectedEvent );nnnfunction handleConnectedEvent( e:SharepointEvent ):voidn{ntrace( “Sharepoint Connected:::”+e.connected );n}nnbrowse_mc.addEventListener( MouseEvent.CLICK, browse);nfunction browse(event:MouseEvent):voidn{n_uploadManager = new UploadManager();n_uploadManager.invoke();n_uploadManager.addEventListener( UploadEvent.UPLOADED, handleUploaded ); }nnfunction handleUploaded(e:UploadEvent):voidn{nvar _fileRef:FileReference = e.fileReference as FileReference; loadedFileName_txt.text = _fileRef.name;nn_sharepoint.addAttachment(handleUploadedResult, “Country”, ‘6’,_fileRef.name, e.byte )n}nnfunction handleUploadedResult(xml:XML)n{ntrace(“Response XML:”+xml)n}

  • Anonymous said:

    Hi, I am getting error on below this line on flashbuilder 4.7 beta.nnbrowse_mc.addEventListener( MouseEvent.CLICK, browse);nnwhat is browse_mc? Why ur using?

  • Anonymous said:

    Hi, I am getting error on below this line on flashbuilder 4.7 beta.nnbrowse_mc.addEventListener( MouseEvent.CLICK, browse);nnwhat is browse_mc? Why ur using?nnThanksnapparao

  • Apparaoj said:

    HI ,nI AM GETTING ERROR ON BLEOW LINE FOR FLASHBUILDER 4.7 BETAnbrowse_mc.addEventListener( MouseEvent.CLICK, browse);n

  • Anonymous said:

    I hope you are new to flex :(nnbrowse_mc is a button where on clicking it open browser dialog box. loadedFileName_txt is a text field which displays the file selected from browser dialog box.nnI dont have flex builder in my machine as of now.nncreate a button of name “loadedFileName_txt”ncreate a textfield of name “loadedFileName_txt”

  • Apparaoj said:

    hi,n app is running fine, but file is not uploading in sharepoint.nplease suggest me…

  • Anonymous said:

    HinnDid you check this linenn_sharepoint.addAttachment(handleUploadedResult, ListName, ID, FileName, Attachment )nnn- *handleUploadedResult:* Process the response XMLn- *ListName:* A string that contains the ListName or the GUID of the SharePoint Listn- *ID:* A String that represents the ID value of SharePoint List item, This is Unique for each rown item.n- *FileName:* Name of the file to be added as attachment.n- *Attachment:* A byte array that contains the file to attach by using base-64 encoding.nnPass proper List GUID as namen http://www.designscripting.com/2011/03/add-attachment-to-sharepoint-2010-list-using-flash-flex-webservice/ n-sara

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.