Hi, I have a site that allows users to upload images. I am able to upload image, save to server, and display images right away. Problem is that the images dissapear after I navigate away from the site! I am using the file system to store images. You can view the site and upload a picture at: http://knudmt.brinkster.net/Inventory.aspx
code-behind is as follows:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class Inventory : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//get the path
getPath();
//file name to string
String img = FileUpload1.FileName.ToString();
//save file for(test)
FileUpload1.SaveAs("C:\\Users\\Matthew\\Documents\\Visual Studio 2005\\WebSites\\WebSite6\\ImageUpload\\" + img);
//offical
//FileUpload1.SaveAs("E:\\Sites\\Single5\\knudmt\\webroot\\ImageUpload\\" + img);
Image1.Visible = true;
Image1.ImageUrl = "~/ImageUpload/" + img;
FileUpload1.Visible = false;
}
protected string getPath()
{
string path = Server.MapPath("Inventory.aspx");
return path;
}
my .aspx page code is as follows, you will see where I attempted to use javascript to solve this issue.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Inventory.aspx.cs" Inherits="Inventory" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language=javascript type="text/javascript">
function setUrl(){
//document.getElementById('tryImg').src = "~/Images/logoChoice.jpg";
//document.getElementById('tryImg').src = "http://localhost
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center" style="width: 800px">
<tr>
<td colspan="3" style="font-size: 23pt; color: #ffffff; font-family: 'Segoe Script';
text-align: left">
<img src="Images/logoChoice.jpg" style="width: 240px; height: 104px; text-align: left" /></td>
</tr>
<tr>
<td colspan="3" style="font-size: 15pt; color: #ffffff; font-family: 'Segoe Script';
height: 21px; background-color: #330033; text-align: center">
About Us</td>
</tr>
</table>
</div>
<table align="center" style="width: 800px">
<tr>
<td colspan="6" style="font-family: 'Segoe Script'; height: 21px; background-color: #669900">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/index.aspx">Home</asp:HyperLink>
<asp:HyperLink ID="HyperLink2" runat="server" NavigateUrl="~/About.aspx">About Us</asp:HyperLink>
<asp:HyperLink ID="HyperLink3" runat="server" NavigateUrl="~/location.aspx">Location</asp:HyperLink>
<asp:HyperLink ID="HyperLink4" runat="server" NavigateUrl="~/contact.aspx">Contact Us</asp:HyperLink>
<asp:HyperLink ID="HyperLink5" runat="server" NavigateUrl="~/Inventory.aspx">Inventory</asp:HyperLink>
<asp:HyperLink ID="HyperLink6" runat="server" Style="text-align: right">Puppy Parade</asp:HyperLink></td>
</tr>
</table>
<br />
<br />
<table align="center" style="width: 800px">
<tr>
<td>
<asp:Image ID="Image1" runat="server" Visible="False" ImageUrl="setUrl();" Width="144px" />
<img name="tryImg" id="tryImg" alt="" src="" visible="true" runat="server" style="width: 144px" /></td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Image ID="Image2" runat="server" Visible="False" Width="144px" /></td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:FileUpload ID="FileUpload2" runat="server" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" /></td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:Image ID="Image3" runat="server" Visible="False" Width="144px" /></td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<asp:FileUpload ID="FileUpload3" runat="server" />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="Button" /></td>
<td>
</td>
<td>
</td>
</tr>
</table>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<table align="center" style="width: 800px">
<tr>
<td colspan="3" style="font-weight: bold; font-size: 13pt; color: #ffffff; font-family: 'Segoe Script';
height: 25px; background-color: #669900; text-align: center">
Tucci's</td>
</tr>
<tr>
<td colspan="3" style="font-weight: bold; font-size: 15pt; color: #ffffff; font-family: 'Segoe Script';
height: 10px; background-color: #330033; text-align: center">
Consignment Furniture</td>
</tr>
<tr>
<td colspan="3">
Tucci's Unique Furnishings<br />
1155 Barret Parkway<br />
Kennesaw GA, 30144<br />
Phone: (770) 296-5888<br />
Fax: (770) 783-8390</td>
</tr>
</table>
</form>
</body>
</html>