-
JavaScript Ability
Is it possible to create files on a webserver by JavaScript?
Also if you can, can you write to them etc?
I mean this so when the JS is ran it creates the file etc.
I know you can do this with more powerful scripting languages, but I'm just trying to find out JS's ability.
-
create a link on a web page. when the user clicks on it it prompts the user for a file name, then created the file on the serverside.
<--snip-->
<script language="VB" runat="server">
Sub CreateFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim strFileName As String = funcParam.Value
'custom code to create a text file
End Sub
</script>
<html>
<head>
<script language="JavaScript">
//ask for user input and then create file
function CreateFile() {
//get filename from the user
var fileName = prompt('Type the name of the file you want to create:','');
//if the user clicks on OK and if they have entered something
if ((fileName) && (fileName!="")) {
//save the filename to the hidden form field 'funcParam'
document.forms['myForm'].elements['funcParam'].value = fileName;
//call the postback function with the right ID
__doPostBack('CreateFile','');
}
}
</script>
</head>
<body>
<form runat="server" id="myForm">
Create Text file
<asp:linkbutton id="CreateFile" runat="server" onclick="CreateFile_Click" />
<input type="hidden" runat="server" id="funcParam">
</form>
</body>
</html>
<---snap-->
for further info goto: http://www.xefteri.com/articles/dec102002/default.aspx
-
ReLik: With just JS, no you cannot create server-side files or write to files.
-
meister, please note that your code will only run on Windows (since it uses ActiveX) and Internet Explorer (since it uses VBScript). Otherwise, yes, it should work.
Cheers,
cgkanchi
-
o.k., of course you're right cgkanchi
:-)