Bonjour,

J'ai actuellement une page qui me permet de mettre à jours un message avec des fichiers joint. Donc j'aimerais qu'au moment de l'update je puisse uploader le fichier avec le controle fileupload qui se toruve sur cette page.

Petite précision, mon formview se trouve dans un updatepanel. Tout fonctionne sans probleme sauf que je ne peux pas faire l'upload de mon fichier.

Malheureusement je n'arrive pas à le recuperer, j'ai essayé divers façon.

Code de la page design

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="EditDoc.aspx.vb" Inherits="loggeduser_EditDoc" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
    <asp:FormView ID="FormView1" runat="server" CellPadding="4" DataSourceID="SqlDataSource1"
        ForeColor="#333333" Width="730px" DefaultMode="Edit" DataKeyNames="id">
        <FooterStyle BackColor="#E3EAEB" Font-Bold="True" ForeColor="White" />
        <EditRowStyle BackColor="#E3EAEB" />
        <EditItemTemplate><asp:Panel ID="Panel2" runat="server" BackColor="#507CD1" Font-Names="Verdana" Font-Size="Larger"
                ForeColor="White" HorizontalAlign="Left">
            Titre Fr:
            <asp:TextBox ID="NomCarteFrUpdateTextBox" runat="server" CssClass="txtbox" Text='<%# Bind("NomCarteFr") %>'></asp:TextBox>&nbsp;
            Titre Nl :
            <asp:TextBox ID="NomCarteNlUpdateTextBox" runat="server" Text='<%# Bind("NomCarteNl") %>'></asp:TextBox></asp:Panel>
            <br />
            <asp:Panel ID="Panel4" runat="server" BackColor="#507CD1" Font-Names="Verdana" Font-Size="Larger"
                ForeColor="White" HorizontalAlign="Left">
                Text Fr</asp:Panel>
            <br />
            <asp:Panel ID="Panel3" runat="server" Font-Names="Verdana" HorizontalAlign="Left">
                <asp:TextBox ID="MemoFrUpdateTextBox" runat="server" CssClass="txtbox" Height="150px" Text='<%# Bind("MemoFr") %>'
                    TextMode="MultiLine" Width="100%"></asp:TextBox></asp:Panel>
            <br />
            <asp:Panel ID="Panel5" runat="server" BackColor="#507CD1" Font-Names="Verdana" Font-Size="Larger"
                ForeColor="White" HorizontalAlign="Left">
                Text Nl</asp:Panel>
            <br />
            <asp:TextBox ID="MemoNlUpdateTextBox" runat="server" CssClass="txtbox" Height="150px" Text='<%# Bind("MemoNl") %>'
                TextMode="MultiLine" Width="100%"></asp:TextBox><br />
            <br />
            <asp:Panel ID="Panel6" runat="server" BackColor="#507CD1" Font-Names="Verdana" Font-Size="Larger"
                ForeColor="White" HorizontalAlign="Left">
                Fichiers</asp:Panel>
            <br />
            <asp:Panel ID="Pfu" runat="server" HorizontalAlign="Left">
                <asp:Label ID="Label3" runat="server" Text='<%# bind("NomPhysFichierFr") %>'></asp:Label>&nbsp;<asp:FileUpload
                    ID="fu1" runat="server" /></asp:Panel>
            <br />
            <br />
            <asp:Panel ID="Panel1" runat="server" BackColor="#507CD1" Font-Names="Verdana" Font-Size="Larger"
                ForeColor="White" HorizontalAlign="Left">
            <table width="100%">            
                <tr>
                    <td style="width:50%">
            <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                Text="Update" ForeColor="White" OnClick="UpdateButton_Click"></asp:LinkButton>&nbsp;
            <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                Text="Cancel" ForeColor="White" OnClick="UpdateCancelButton_Click"></asp:LinkButton>
                    </td>
                    <td style="width:50%;" align="right">
                <asp:Label ID="Label1" runat="server" Text="Modifié le : "></asp:Label>
                <asp:Label ID="Label2" runat="server" Text='<%# bind("datemodif") %>'></asp:Label>
                    </td>
                </tr>
             </table>             
             </asp:Panel>
        </EditItemTemplate>                      
        <RowStyle BackColor="#EFF3FB" />
        <PagerStyle BackColor="#E3EAEB" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#E3EAEB" Font-Bold="True" ForeColor="White" />
    </asp:FormView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CS_MAG %>" 
        SelectCommand="SELECT [NomCarteFr], [NomCarteNl], [MemoFr], [MemoNl], [Id], [DateModif], [NomPhysFichierFr] FROM CartesVisites WHERE ([Id] = @Id)" 
        UpdateCommand="UPDATE [CartesVisites] SET [NomPhysFichierFr]=@NomPhysFichierFr,[MemoFr] = @MemoFr,[MemoNl] = @MemoNl,[NomCarteFr] = @NomcarteFr,[NomCarteNl] = @NomcarteNl, DateModif =  { fn NOW() }  WHERE ([Id] = @original_id)" OldValuesParameterFormatString="original_{0}">
        <SelectParameters>
            <asp:QueryStringParameter Name="Id" QueryStringField="id" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="MemoFr" Type="String" />
            <asp:Parameter Name="NomCarteFr" Type="String" />
            <asp:Parameter Name="MemoNl" Type="String" />
            <asp:Parameter Name="NomCarteNl" Type="String" />
            <asp:Parameter Name="NomPhysFichierFr" Type="String" />            
            <asp:Parameter Name="original_id" />
        </UpdateParameters>
    </asp:SqlDataSource>
            <br />
            <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                <ProgressTemplate>
                    <asp:Image ID="Image1" runat="server" CssClass="txtbox" ImageUrl="~/images/Wait.gif" />
                </ProgressTemplate>
            </asp:UpdateProgress>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
Code behind

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
 
Partial Class loggeduser_EditDoc
    Inherits System.Web.UI.Page
 
    Protected Sub FormView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles FormView1.ItemUpdating        
        'MsgBox(Me.FormView1.Controls.Item(0).Controls(0).ID)
    End Sub
 
    Protected Sub UpdateCancelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Redirect("displayC.aspx?id=" & Request.QueryString("id"))
    End Sub
 
    Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)                
        'MsgBox(CType(Me.FormView1.FindControl("pfu").FindControl("fu1"), FileUpload).FileName)
        'MsgBox(Me.FormView1.Controls.Item(0).ID)        
    End Sub
End Class
j'ai essayé avec des findcontrol, des controls(0). ... mais rien y fais.

Une idee...