Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to create a html form, in that form when I click on submit option at the end it should save directly in a document library(I should not upload it manually)

Can anyone tell me the possibilities for this!!
Posted

If your question is that you will have file upload control in your html form and it should be uploaded to Sharepoint document library upon submission of form, you can implement it using webservices.

Below is sample code to upload document using webservices.

XML
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
    function uploadFile() {
        var filePath = "c:\\SampleFile.pdf";
        var soapEnv =
        "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soap:Body>\
                <CopyIntoItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>\
                    <SourceUrl>" + filePath + "</SourceUrl>\
                        <DestinationUrls>\
                            <string>http://sharepointsite/Shared Documents/test.pdf</string>\
                        </DestinationUrls>\
                        <Fields>\
                            <FieldInformation Type='Text' DisplayName='Title' InternalName='Title' Value='Test' />\
                        </Fields>\
                    <Stream>base64Binary</Stream>\
                </CopyIntoItems>\
            </soap:Body>\
        </soap:Envelope>";

        $.ajax({
            url: "http://sharepointsite/_vti_bin/copy.asmx",
            beforeSend: function (xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"); },
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });
    }


    function processResult(xData, status) {
        alert("Uploaded SuccessFully");
    }
</script>
<input type="button" onclick="uploadFile()" name="Upload" />


It might also be available through Client Object Model or SPServices.
 
Share this answer
 
$("#uploadDocumentButton").click(function () {
if (window.FileReader) {
input = document.getElementById("inputFile");
if (input) {
file = input.files[0];
fr = new FileReader();
fr.onload = receivedBinary;
fr.readAsDataURL(file);
}
}
else {
alert("The HTML5 FileSystem APIs are not fully supported in this browser.");
}
});

function receivedBinary() {
var url = _spPageContextInfo.webAbsoluteUrl;
var clientContext = new SP.ClientContext(url);
web = clientContext.get_web();
parentList = web.get_lists().getByTitle('Shared Documents');
fileCreateInfo = new SP.FileCreationInformation();
fileCreateInfo.set_url(file.name);
fileCreateInfo.set_overwrite(true);
fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
var arr = convertDataURIToBinary(this.result);
for (var i = 0; i < arr.length; ++i) {
fileCreateInfo.get_content().append(arr[i]);
}
this.newFile = parentList.get_rootFolder().get_files().add(fileCreateInfo);

clientContext.load(this.newFile, 'ListItemAllFields');
var item = this.newFile.get_listItemAllFields();

item.update();

clientContext.executeQueryAsync(onSuccess, onFailure);
}




<bold>Try this one
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900