Relative path of images in database depending on folder in solution

Instantempoky28

New Member
I have an .aspx page called editprofile which can be found inside of my ~/Account/ folder . The page itself allows users to upload a new user avatar, change their details etc. When the image is saved, it is saved into a table ('userprofiles') into a field called AvatarURL with a relative path like so: UserProfileAvatar/image.jpgI have a separate page which is in the main solution directory above called detail.aspx. I had a problem with the image not appearing when I try to display it, and found out that this is because the path written into the database is relative to the 'Account' folder. I have managed to get this working by editing a record in my database and appending the extra level on top of it as so: Account/UserProfileAvatar/image.jpg and the image appears.How do I compensate for environmental factors such as this so that different pages in my solution (wherever they are in the folder hierarchy) can reference images placed in this folder without any trouble?Here is my code behind:\[quote\]\[code\]Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim sql Dim cmd Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("BookMeetConnString").ConnectionString) If Not fu_avatar.HasFile Then sql = "UPDATE userprofiles SET EmailAddress=@f1, Description=@f2 WHERE TravellerName=@f3" cmd = New OleDbCommand(sql, conn) cmd.Parameters.AddWithValue("@f1", email.Text) cmd.Parameters.AddWithValue("@f2", description.Text) cmd.Parameters.AddWithValue("@f3", User.Identity.Name) Else sql = "UPDATE userprofiles SET EmailAddress=@f1, Description=@f2, AvatarURL=@f3 WHERE TravellerName=@f4" cmd = New OleDbCommand(sql, conn) cmd.Parameters.AddWithValue("@f1", email.Text) cmd.Parameters.AddWithValue("@f2", description.Text) cmd.Parameters.AddWithValue("@f3", "UserProfileAvatar/" & User.Identity.Name & ".jpg") cmd.Parameters.AddWithValue("@f4", User.Identity.Name) Dim fileLocationOnServerHardDisk = Request.MapPath("UserProfileAvatar") & "/" & User.Identity.Name & ".jpg" fu_avatar.SaveAs(fileLocationOnServerHardDisk) End If conn.Open() cmd.ExecuteNonQuery() conn.Close() DisplayData() SaveConfirmation.Visible = TrueEnd Sub\[/code\]\[/quote\]
 
Back
Top