You can do this in native JavaScript. You'll have to parse your data into correct CSV format as so (assuming you are using an array of arrays for your data as you have described in the question):
const rows = [
["name1", "city1", "some other info"],
["name2", "city2", "more info"]
];
let csvContent = "data:text/csv;charset=utf-8,";
rows.forEach(function(rowArray) {
let row = rowArray.join(",");
csvContent += row + "\r\n";
});
or the shorter way (using arrow functions):
const rows = [
["name1", "city1", "some other info"],
["name2", "city2", "more info"]
];
let csvContent = "data:text/csv;charset=utf-8,"
+ rows.map(e => e.join(",")).join("\n");
Then you can use JavaScript's window.open
and encodeURI
functions to download the CSV file like so:
var encodedUri = encodeURI(csvContent);
window.open(encodedUri);
Edit:
If you want to give your file a specific name, you have to do things a little differently since this is not supported accessing a data URI using the
window.open
method. In order to achieve this, you can create a hidden
<a>
DOM node and set its
download
attribute as follows:
var encodedUri = encodeURI(csvContent);
var link = document.createElement("a");
link.setAttribute("href", encodedUri);
link.setAttribute("download", "my_data.csv");
document.body.appendChild(link); // Required for FF
link.click(); // This will download the data file named "my_data.csv".
Yes. You can specify the TemplateType
for your List
.
List of TemplateTypes
using (ClientContext clientCTX = new ClientContext(url))
{
ListCreationInformation lci = new ListCreationInformation();
lci.Description = "My own DocLib";
lci.Title = "Library";
lci.TemplateType = 101;
List newLib = clientCTX.Web.Lists.Add(lci);
clientCTX.Load(newLib);
clientCTX.ExecuteQuery();
}
Best Answer
Just found this while searching for the same thing, but it looks like Sharepoint 2010 has something built in for this, at least for the Server model:
list.Fields.ContainsField("fieldName");
Not sure if it exists for Client side though. Figured it would be a good place to store this information however.