Aug 25, 2016, 11:57 AM
[CLOSED] file uploader
Hi,
I am using your example for uploading a file, but when it comes to the "if (this.FileUploadField1.HasFile)" it is false when I am using a tool from the window to save. for testing purposes I tried using a direct event from the fileuploader and it works from there. But I need to upload the file during the save event, not before. please advise.
I am using your example for uploading a file, but when it comes to the "if (this.FileUploadField1.HasFile)" it is false when I am using a tool from the window to save. for testing purposes I tried using a direct event from the fileuploader and it works from there. But I need to upload the file during the save event, not before. please advise.
<%@ Control Language="C#" %>
<ext:DesktopModuleProxy ID="DesktopModuleProxy1" runat="server">
<Module ModuleID="create-test">
<Shortcut Name="test" IconCls="x-edits-shortcut" SortIndex="1" />
<Launcher Text="test" Icon="Table" />
<Window>
<ext:Window ID="Window1" runat="server" Width="500" Height="200">
<Tools>
<ext:Tool Type="Save" ToolTip="Save information" >
<DirectEvents>
<Click OnEvent="UploadClick" /> <%--from here it does not work!!!--%>
</DirectEvents>
</ext:Tool>
</Tools>
<Items>
<ext:FormPanel ID="FormPanel1" runat="server">
<Items>
<ext:FileUploadField runat="server" FieldLabel="Company Logo" EmptyText="Select an image" ButtonText="" ID="FileUploadField1" Icon="ImageAdd" >
<LeftButtons>
<ext:Button runat="server">
<DirectEvents>
<Click OnEvent="UploadClick" /> <%--from here it works--%>
</DirectEvents>
</ext:Button>
</LeftButtons>
</ext:FileUploadField>
</Items>
</ext:FormPanel>
</Items>
</ext:Window>
</Window>
</Module>
</ext:DesktopModuleProxy>
and in the code CodeBehind public void UploadClick(object sender, DirectEventArgs e)
{
string tpl = "Uploaded file: {0}<br/>Size: {1} bytes";
if (this.FileUploadLogo.HasFile)
{
//FileUploadLogo.PostedFile.SaveAs(
X.Msg.Show(new MessageBoxConfig
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.INFO,
Title = "Success",
Message = string.Format(tpl, this.FileUploadLogo.PostedFile.FileName, this.FileUploadLogo.PostedFile.ContentLength)
});
}
else
{
X.Msg.Show(new MessageBoxConfig
{
Buttons = MessageBox.Button.OK,
Icon = MessageBox.Icon.ERROR,
Title = "Fail",
Message = "No file uploaded"
});
}
}
Last edited by Daniil; Sep 01, 2016 at 3:39 PM.
Reason: [CLOSED]