Question

I’m working on a project that uses SharePoint 2010. I need to write a POST variable to a file using an ajax call.

If I were using PHP I would use the fwrite() function to write the POST to a file.

Here is how I envision my solution working. When you go to notarealwebsite.com and submit the form, I envision using an ajax call to write the file. The ajax on the index.php would look like:

$.ajax({
    type: 'POST',
    url: 'save-text.php',
    data: {json: JSON.stringify(strJson)}
});

In PHP I would pass the POST variable into the save-text.php file and its code would look like this:

<? php
$file = fopen("file.txt","w");
fwrite($file, $_POST['json']);
fclose($file);
?>

Does SharePoint have an equivalent function I can use to save the POST to a file?

Was it helpful?

Solution

You don't give us too much here...

You can develop something in JavaScript using a third library like SharepointPlus with the createFile function

You'll do:

$SP().createFile({
  content: JSON.stringify(strJson),
  destination: "http://mysite/Shared Documents/file.txt",
  url:"http://mysite/",
  after:function() {
    alert("File saved");
  }
});

The createFile of SharepointPlus uses the CopyIntoItems web service of Sharepoint.

OTHER TIPS

In SharePoint environment, you would most probably write these strings to list instead of file system. This is especially true if its some kind of configuration value because you want it accessible from all the frond end machines. A file on a filesystem will be created on just a single node where the code runs ultimately after the load balancer.

See: How to: Create, Update, and Delete List Items
http://msdn.microsoft.com/en-us/library/office/ee539976(v=office.14).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top