J'essaie de créer un fichier avec asp qui invite l'utilisateur à donner un nom de fichier, puis il va exécuter Sub CreateFile_Click qui va créer le nouveau fichier. Le nouveau fichier doit avoir le même nom que l'utilisateur entré dans l'invite.Comment créer un nouveau fichier avec asp.net?
pour une raison im obtenir
+System.IO.File.Create(filepath).Dispose()
{"Access to the path 'C:\futu.txt' is denied."}
System.UnauthorizedAccessException
<script language="VB" runat="server">
Sub CreateFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim strFileName As String = funcParam.Value
Dim filepath as String = "C:\futu.txt"
If Not System.IO.File.Exists(filepath) Then
System.IO.File.Create(filepath).Dispose()
End If
'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">
<a href="javascript:CreateFile();">Create Text file</a>
<asp:linkbutton id="CreateFile" runat="server" onclick="CreateFile_Click" />
<input type="hidden" runat="server" id="funcParam">
</form>
</body>
</html>
Vous n'aurez accès qu'à 'c:' dans une application Windows, l'application ASP.NET à laquelle vous avez accès, ce sont les dossiers du dossier racine de l'application, par exemple 'C: \ inetpup \ mysite' – balexandre