protected void btnupload_Click(object sender, EventArgs e) { if (PhotoUpload1.HasFile) { Session["ImageBytes"] = PhotoUpload1.FileBytes; string str = Server.MapPath(PhotoUpload1.FileName); ImagePreview.ImageUrl = "~/DriverSetup/" + PhotoUpload1.FileName; } }
<pre lang="xml"><asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Image CssClass="img img-thumbnail" Width="150px" Height="180px" ID="ImagePreview" runat="server" /> <br /> <asp:FileUpload ID="PhotoUpload1" runat="server" /> <br /> <asp:Button ID="btnupload" runat="server" Text="Upload" onclick="btnupload_Click" /> <asp:UpdateProgress ID="UpdateProgress1" runat="server"> <ProgressTemplate>Please wait...</ProgressTemplate> </asp:UpdateProgress> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="btnupload" /> </Triggers> </asp:UpdatePanel> </pre>
protected void UploadButton_Click(object sender, EventArgs e) { if(FileUploadControl.HasFile) { try { if(FileUploadControl.PostedFile.ContentType == "image/jpeg") { if(FileUploadControl.PostedFile.ContentLength < 102400) { string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/") + filename); StatusLabel.Text = "Upload status: File uploaded!"; } else StatusLabel.Text = "Upload status: The file has to be less than 100 kb!"; } else StatusLabel.Text = "Upload status: Only JPEG files are accepted!"; } catch(Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } }
<Triggers> <asp:PostBackTrigger ControlID="btnupload" /> </Triggers> </asp:UpdatePanel>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)