0

I am having CSV with more than 3500 records. My need is to import the CSV data to SharePoint 2013 custom list.

I have to achieve this programmatically.

I have already tried some bulk operations/Batch insert operations but all the options came into picture from SharePoint Online and SharePoint 2016 or later.

So is there any way in SharePoint 2013 to import CSV to SharePoint list programmatically?

Also I do not want to iterate the records and insert the data in SharePoint list.

I am looking for JavaScript based solution.

0

The Rest API is identical (As far as I know) between 2013 and 2013/Online. So you should be able to use this Rest endpoint:

http://site url/_api/web/lists/GetByTitle('Test')/items

Documentation for the Rest API is here: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest

I'm not very proficient in javascript, but it would seem there's quite a few snippets you could use. Maybe this will get you started:

// occurs when a user clicks the create button
function CreateNew() {
    var listName = "MyList";
    var newItemTitle = "New Title Item";
    CreateListItemWithDetails(listName, _spPageContextInfo.webAbsoluteUrl, newItemTitle, function () {
        alert("New Item has been created successfully.");
 }, function () {
     alert("Ooops, an error occured. Please try again.");
 });
}

// CREATE Operation
// listName: The name of the list you want to get items from
// weburl: The url of the web that the list is in. 
// newItemTitle: New Item title.
// success: The function to execute if the call is sucesfull
// failure: The function to execute if the call fails
function CreateListItemWithDetails(listName, webUrl, newItemTitle, success, failure) {
    var itemType = GetItemTypeForListName(listName);
    var item = {
        "__metadata": { "type": itemType },
        "Title": newItemTitle
    };

    $.ajax({
        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            success(data);
        },
        error: function (data) {
            failure(data);
        }
    });
}

// Get List Item Type metadata
function GetItemTypeForListName(name) {
    return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}

Found here: https://tjendarta.wordpress.com/2014/02/20/create-retrieve-update-and-delete-sharepoint-list-item-using-rest-api-and-jquery/

And referenced here: Adding new list item using REST

  • Please do that. Another approach could be to create a site workflow that uses the rest api to loop through the items in your cvs-file. You would need to create a list based the csv file by uploading it and then interate through the list. I've used this approach a few times in the past. But I think the javascript approach is faster (if you know your way around javascript) :-) – Morten K Nov 8 '17 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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