<asp:FileUpload ID="fuImage" Width="320" EnableTheming=true runat="server" Visible="true" /> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"><asp:Button runat="server" ID="btnUploadImage" OnClick="UploadImage" Text="Upload Facility Image" Visible="true" ></asp:Button></font> </td>
Protected Sub UploadImage(ByVal sender As Object, ByVal e As EventArgs) Try Dim saveDir As String = ConfigurationManager.AppSettings.Item("BaseApplicationFolder") ' Get the physical file system path for the currently ' executing application. Dim appPath As String = Request.PhysicalApplicationPath If Not FACID = txtFacId.Text And Not String.IsNullOrEmpty(txtFacId.Text) Then FACID = txtFacId.Text End If ' Before attempting to save the file, verify ' that the FileUpload control contains a file. If (fuImage.HasFile) Then Dim savePath As String = appPath + "_images\assisted_living\fac_profile_pic\" + _ Server.HtmlEncode(fuImage.FileName) If fuImage.FileName.Contains(FACID) Then ' Call the SaveAs method to save the uploaded file to the specified path. ' If a file with the same name already exists in the specified path, the uploaded file overwrites it. If (File.Exists(savePath)) Then File.Delete(savePath) End If fuImage.SaveAs(savePath) Fac_picture.ImageUrl = "..\..\_images\assisted_living\fac_profile_pic\" + FACID + ".jpg" fuImage.DataBind() Else lbl_message.Text = "The image name and facility name should match." End If End If Catch ex As Exception lbl_message.Text = ex.Message End Try End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)