I used FileUpload control on my SharePoint UserControl. Even after choosing
a file,it shows FileUpload Control's "hasfile" property as false.
<asp:UpdatePanel ID="UPanProcesses" runat="server">
<ContentTemplate>
<asp:FileUpload ID='FileUploadPhoto' runat="server" />
<asp:Button ID="ButtonSave" runat="server" Text="Enregistrer" OnClick="ButtonSave_Click" ></asp:Button>
</ContentTemplate>
</asp:UpdatePanel>
Code Behind :
protected void ButtonSave
_Click(object sender, EventArgs e)
{
if
(FileUploadPhoto.HasFile)
{
byte[] data = FileUploadPhoto.FileBytes;
item.Attachments.Add(FileUploadPhoto.FileName, data);
}
}
The solution :
Add a trigger for your UpdatePanel
<Triggers>
<Triggers>
<asp:PostBackTrigger ControlID="ButtonSave" />
</Triggers>
This will force a postback when the upload button is clicked.
Also add the line below to the Page_Load
Page.Form.Attributes.Add("enctype", "multipart/form-data");
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID=" ButtonSave " />
</Triggers>
</asp:UpdatePanel>
protected void Page_Load(object sender, EventArgs e)
{
Page.Form.Attributes.Add("enctype", "multipart/form-data");
}
Enregistrer un commentaire