AddAttachment, SP2007, FileUpload

Feb 12, 2014 at 1:37 PM
Edited Feb 12, 2014 at 1:38 PM
Copied from:
Reported on: Today at 5:08 AM
Reported by: Shaolino


The Situation: I've build a website to offer a custom build input form for a Sharepoint-List.

The Used Languages: HTML 4.0.1, CSS, JavaScript, JQuery (1.11.0), SPServices (0.7.2), Sharepoint 2007 Basic
--> each language seperated in own files

Tools: Not supported (no InfoPath, no SP-Designer)

The Task: Attach a file to the last List-Item.

Way so far: Works fine already to write input data type=text with UpdateListItems and New batchCMD into Sharepoint-List. --> Input Field type=file in HTML Page created to support attachment upload to the list.

The Problem: AddAttachment runs clear through without adding the attachment and without throwing errors in the browser. When alerting the file input, "undefined" is the message showen.

The Question: Is there a way to get the file from the HTML input field and to give it to SPServices to write it down in the SP-List? Something like a handler? I've read that the input is needed in 64Byte encoded. The attachment will be a local stored Excel file, from the users client PC. Will it still work after encoding? And is there an easy solution for handle and encode the file?

Thanks for your help
Feb 12, 2014 at 1:39 PM
Can you show the code you're trying to use with AddAttachment?

Feb 13, 2014 at 7:55 AM
Yes HTML file
<input type="file" name="Attachment" id="Attachment" tabindex="6"></input></td> .js file
var itemID = $().SPServices.SPGetLastItemId({
            listName: "MyList"
var theFile = $("#Attachment").prop("files");
                operation: "AddAttachment",
                listName: "MyList",
                async: false,
                listItemID: itemID,
                fileName: "test.xlsx",
                attachment: theFile,
                completefunc: function(xData, Status){
                    alert("upload complete");
I tryed differend ways to get theFile. Nothing helped. But with this setup it runs clear through. The fileName is static in this case for testing purpose. If I alert theFile, "undefined" is the result message.
Yet I have not found any Tutorial- or Helpingpage on the net, where the whole process of getting data from a Website (html 4.0.1) into Sharepoint 2007 is described.
With html5 things would be much easier as there is the FileReader(). But I have to use those older versions. That's my liability.

Thanks for your help
Feb 13, 2014 at 11:48 AM
There is no "direct" way to do it without HTML5. Mainly, because as you already know, you need to get the content of the file as a BASE64 stream.

I created an Upload widget a few years ago, but it works on Document Libraries only and not Lists. It uses the built in SP Upload.aspx page in an iframe. Maybe this approach is something you can think about to solve your business use case.

Paul T.

-- Sent from Mobile

Feb 13, 2014 at 12:35 PM
ptavares wrote:
There is no "direct" way to do it without HTML5.
I think my boss will have to live with this fact and think about investing in some modern components to work on.

For me it is good to know that my file handling wasn't completly wrong done. When I have enough time left on this project, I'll try your widget.
Is there a link, where to get it? Maybe I would try to upload the files to a library and copy them to the item as an attachment.
I am thankful for every help I can get.

Thank you for this fast reply! :)
Feb 13, 2014 at 12:44 PM
Ok. I get the feeling you know what you are doing. I was going to suggest that approach (use a Doc library as a temporary staging location) but because of the complexity, I held off. But your thinking along the same line.

You should download the latest from github, since I have made some fixes but have not yet cut a new version.

Your approach should be:

1. Upload file to Doc library
2. Read the file from the doc library (I believe the copy service has a API method to do this). The file content (I think) will already be returned as BASE64 - but not sure.
3. Write that file to the List item (remember: you may have to check out the item if the list has checkout turned on)
4. Delete the temporary file in the doc library

Paul T.

-- Sent from Mobile

Feb 13, 2014 at 2:41 PM
Thanks! :)

As soon as I got a solution for this problem, i'll post it here. (could take a while, but also the longest path begins with the first step)

Have a nice day! :)