I have designed a Form for Announcement list, I want to write a code on the Save button, which could save a file attached (browse/fileupload button) by user in the form (check screenshot). I want to save this attached file in a specific Library.

I am designing this in Sharepoint Designer 2010. How can I write a simple c# code for the same, I do not find code behind this form.

enter image description here

1 Answer 1


There is no code behind file associated with the custom form created using the designer. You should write JavaScript client object model code to perform the task. It can be written inside the designer. Here is a sample code to upload file to library:

"use strict";

var WingtipToys = window.WingtipToys || {};
WingtipToys.Jsom = WingtipToys.Jsom || {};

WingtipToys.Jsom.Libs = function () {

    var deferreds = new Array(),

    upload = function (serverRelativeUrl, filename, file) {
        deferreds[deferreds.length] = $.Deferred();

            function (buffer) {
                var bytes = new Uint8Array(buffer);
                var content = new SP.Base64EncodedByteArray(); //base64 encoding
                for (var b = 0; b < bytes.length; b++) {
                var ctx = new SP.ClientContext.get_current();
                var createInfo = new SP.FileCreationInformation();
                createInfo.set_content(content); //setting the content of the new file
                this.files = ctx.get_web().getFolderByServerRelativeUrl(serverRelativeUrl).get_files();
                        function () { deferreds[deferreds.length - 1].resolve(this.files); }),
                        function (sender, args) { deferreds[deferreds.length - 1].reject(sender, args); }));

            function (err) {
                deferreds[deferreds.length - 1].reject(err);

        return deferreds[deferreds.length - 1].promise();


    getFileBuffer = function (file) {
        //See previous code

    return {
        upload: upload,


Source: http://www.shillier.com/archive/2013/03/26/uploading-files-in-sharepoint-2013-using-csom-and-rest.aspx

When a Save button is clicked in a SharePoint form the OOB JavaScript function PreSaveAction is called. This can be overridden to add support for uploading the file. See here for more information about it: http://sharepointwings.blogspot.in/2012/06/javascript-presaveaction-in-sharepoint.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.