Bonjour
Je suis de niveau débutant (aspx / VB.Net) et suite au premier poste ( http://www.aspfr.com/forum/sujet-UPLOADER-VERS-MON-SERVEUR-DISTANT_1351762.aspx ), je suis confronté à un problème.
Vous trouverez le script et le message d'erreur (problème) ci-dessous:
LE SCRIPT:
<%@ Page Explicit="True" Language="VB" Debug="True" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Upl.aspx</title>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Labelc1.Text = ""
Dim path As String = Server.MapPath("http://www.monsiteweb.com/www/images/")
Dim fileOK As Boolean = False
If FileUpload1.HasFile Then
Dim fileExtension As String
fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower()
Dim allowedExtensions As String() = {".jpg", ".gif"}
For i As Integer = 0 To allowedExtensions.Length - 1
If fileExtension = allowedExtensions(i) Then
fileOK = True
End If
Next
If fileOK Then
Try
FileUpload1.PostedFile.SaveAs(path & FileUpload1.FileName)
Labelc1.Text = "Le fichier a été chargé."
Catch ex As Exception
Labelc1.Text = "Problème ! Le fichier n'a pas pu être chargé."
End Try
Else
Labelc1.Text = "Les extensions doivent être de type .jpg ou .gif"
End If
Else
Labelc1.Text = "Pas de fichier sélectionné"
End If
End Sub
</script>
</head>
<body>
<form runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Envoyer"/>
<asp:Label ID="Labelc1" runat="server" Text=""/>
</form>
</body>
</html>
LE MESSAGE D'ERREUR:
Source Error:
Line 27: If fileOK Then
Line 28:
Line 29: FileUpload1.PostedFile.SaveAs(path & FileUpload1.FileName)
Line 30:
Line 31: Else
Source File: d:\www\monsiteweb\www\upl.aspx Line: 29
Stack Trace:
[UnauthorizedAccessException: Access to the path 'd:\www\monsiteweb\www\images\monimage.gif' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +651
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1038
System.IO.FileStream..ctor(String path, FileMode mode) +64
System.Web.HttpPostedFile.SaveAs(String filename) +87
ASP.upl_aspx.Button1_Click(Object sender, EventArgs e) in d:\www\monsiteweb\www\upl.aspx:29
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746