Hi,
I am trying to write data in a existing text file , which present in my Site Collection Documents , The problem is whenever I try to write into that file the new data is written into the file , I want to add data to , means the previous data should not go.
Please suggest a way !
I am using this code :
function createFile(resultpanel) {
var clientContext;
var oWebsite;
var oList;
var fileCreateInfo;
var fileContent;
clientContext = new SP.ClientContext.get_current();
oWebsite = clientContext.get_web();
oList = oWebsite.get_lists().getByTitle("Shared Documents");
fileCreateInfo = new SP.FileCreationInformation();
fileCreateInfo.set_url("my new file.txt");
fileCreateInfo.set_content(new SP.Base64EncodedByteArray());
fileContent = "The content of my new file";
for (var i = 0; i < fileContent.length; i++) {
fileCreateInfo.get_content().append(fileContent.charCodeAt(i));
}
this.newFile = oList.get_rootFolder().get_files().add(fileCreateInfo);
clientContext.load(this.newFile);
clientContext.executeQueryAsync(
Function.createDelegate(this, successHandler),
Function.createDelegate(this, errorHandler)
);
function successHandler() {
resultpanel.innerHTML =
"Go to the "+
"<a href='../Lists/Shared Documents'>document library</a> "+
"to see your new file.";
}
function errorHandler() {
resultpanel.innerHTML = "Request failed: "+ arguments[1].get_message();
}
}