IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

Problème AsyncFileUpload renvoi le fichier


Sujet :

ASP.NET

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Août 2006
    Messages
    228
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 228
    Points : 60
    Points
    60
    Par défaut Problème AsyncFileUpload renvoi le fichier
    Bonjour,

    Je n'arrive pas à vider le composant lorsque le fichier est chargé.

    Si j'ai un autre bouton sur la page, il renvoie à nouveau le fichier.

    Merci pour votre aide.

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Août 2006
    Messages
    228
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 228
    Points : 60
    Points
    60
    Par défaut
    J'ai testé une fonction que j'ai trouvée sur internet :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        {
            string filename = ConfigurationManager.AppSettings["URLDocument"] + AsyncFileUpload1.PostedFile.FileName;
            AsyncFileUpload1.SaveAs(filename);
            Page.Controls.Remove(AsyncFileUpload1);
        }
    Hélàs sans succès. Même avec la partie javascript

  3. #3
    Expert confirmé

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2010
    Messages
    2 065
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2010
    Messages : 2 065
    Points : 4 229
    Points
    4 229
    Par défaut
    c'est quoi ton code d'envoi ?

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Août 2006
    Messages
    228
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 228
    Points : 60
    Points
    60
    Par défaut
    Le code aspx :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test-Components.aspx.cs" Inherits="Test_Components" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type = "text/javascript">
            function uploadComplete(sender) {
                $get("activity").style.visibility = 'hidden';
                $get("<%=lblMesg.ClientID%>").innerHTML = "Chargement de votre pièce jointe réussi.";
                   //Clear the file name textbox
     
               var ctrlText = sender.get_element().getElementsByTagName("input");
               for (var i = 0; i < ctrlText.length; i++) {
                  if (ctrlText[i].type == "text") {
                     ctrlText[i].value = "";
                     ctrlText[i].style.backgroundColor = "white";
                  }
               }
            }
            function uploadError(sender) {
                $get("<%=lblMesg.ClientID%>").innerHTML = "Erreur pendant le chargement.";
            }
            function uploadStarted(sender) {
                $get("AsyncFileUpload1").style.visibility = 'hidden';
            }
        </script>     
    </head>
    <body>
        <form id="form1" runat="server">
        <ajaxToolkit:ToolkitScriptManager runat="server" />
        <div>
            <ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" runat="server" 
                ViewStateMode="Enabled" ThrobberID="activity" 
                onuploadedcomplete="AsyncFileUpload1_UploadedComplete" 
                onuploadedfileerror="AsyncFileUpload1_UploadedFileError" 
                CompleteBackColor="Lime" ErrorBackColor="Red" OnClientUploadError="uploadError" 
                OnClientUploadComplete="uploadComplete" OnClientUploadStarted="uploadStarted" 
                PersistFile="True" />
            <img src="images/activity.gif" runat="server" id="activity" alt="Chargement en cours ..." title="Chargement en cours ..." />
            <br /> 
            <asp:Label ID="lblMesg" runat="server" Text="" />
            <br /><br />
            <asp:Button ID="Button1" runat="server" Text="Sauvegarder" onclick="Button1_Click" />
            <br />
            <asp:Label ID="LbSauvegarde" runat="server" Text="Avant click" />
        </div>
        </form>
    </body>
    </html>
    Le .cs :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
     
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using MySql.Data.MySqlClient;
    using System.Net.Mail;
    using System.IO;
    using System.Text.RegularExpressions;
    using System.Text;
    using Bitly;
     
    public partial class Test_Components : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
     
        }
        protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        {
            string filename = ConfigurationManager.AppSettings["URLDocument"] + AsyncFileUpload1.PostedFile.FileName;
            AsyncFileUpload1.SaveAs(filename);
            Page.Controls.Remove(AsyncFileUpload1);
        }
        protected void AsyncFileUpload1_UploadedFileError(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
        {
     
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            LbSauvegarde.Text = "Après click";
        }
    }

  5. #5
    Expert confirmé

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2010
    Messages
    2 065
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2010
    Messages : 2 065
    Points : 4 229
    Points
    4 229
    Par défaut
    une technique pour effacer le contenu du contrôle j'espère ça t'aidera:
    http://www.aspsnippets.com/Articles/...e-revisit.aspx
    et dans ton upload completed dans le codebehind tu peux vérifier si il y a un fichier dedans avant de le sauvegarder avec
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    AsyncFileUpload1.HasFile

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Août 2006
    Messages
    228
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 228
    Points : 60
    Points
    60
    Par défaut
    Merci Youtpout, je regarde ça demain et je te dirais si ça marche

Discussions similaires

  1. Problème renvoie dans fichier LOG
    Par legomaniac071 dans le forum VBScript
    Réponses: 8
    Dernier message: 23/05/2012, 15h34
  2. [FTP] Problème pour uploader un fichier
    Par Crazyblinkgirl dans le forum Entrée/Sortie
    Réponses: 10
    Dernier message: 07/01/2008, 22h21
  3. Problème pour Télécharger des fichiers
    Par joce3000 dans le forum C++Builder
    Réponses: 8
    Dernier message: 21/01/2005, 10h30
  4. Réponses: 4
    Dernier message: 16/04/2004, 08h20
  5. [langage] Problème de taille de fichier à mettre dans
    Par And_the_problem_is dans le forum Langage
    Réponses: 10
    Dernier message: 13/08/2002, 09h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo