HELP!
Trying to write code to allow a user to upload an image, but then to add the name to a database for future retrieval.
I have the upload sorted but need help getting started with adding the data to a database. Please could someone help?
Regards
<% @Page Language="C#" %>
<html>
<head>
<title>Logo Upload Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="general.css">
<style type="text/css">
</style>
</head>
<body background="main.gif">
<p align="right"><span class="highlight_title"><strong>Logo Upload Page</strong></span></p>
<p>This page has been developed so that the logos
can be uploaded.
</p>
<ul>
<li><em>1) A single logo per user is allowed.</em></li>
<li><em>2) Use the browse button to find the new image on your computer (or server).</em></li>
<li><em>3) Type the name of the image file in the "Name on Server" box</em></li>
<li><em>4) Click "Upload" to confirm the upload</em></li>
</ul>
<p>
<script language="C#" runat="server">
void btnUploadTheFile_Click(object Source, EventArgs evArgs)
{
string strFileNameOnServer = txtServername.Value;
string strBaseLocation = "d:\\domains\\wwwroot\\logos\\";
if ("" == strFileNameOnServer)
{
txtOutput.InnerHtml = "Error - a file name must be specified.";
return;
}
if (null != uplTheFile.PostedFile)
{
try
{
uplTheFile.PostedFile.SaveAs(strBaseLocation+strFileNameOnServer);
txtOutput.InnerHtml = "File <b>" +
strBaseLocation+strFileNameOnServer+"</b> uploaded successfully";
}
catch (Exception e)
{
txtOutput.InnerHtml = "Error saving <b>" +
strBaseLocation+strFileNameOnServer+"</b><br>"+ e.ToString();
}
}
}
</script>
</p>
<table>
<form enctype="multipart/form-data" runat="server">
<tr>
<td><font size=1>Select file:</font></td>
<td>
<input id="uplTheFile" type=file runat="server">
</td>
</tr>
<tr>
<td><font size=1>Name on server:</font></td>
<td>
<input id="txtServername" type="text" runat="server">
</td>
</tr>
<tr>
<td colspan="2">
<input type=button id="btnUploadTheFile" value="Upload"
OnServerClick="btnUploadTheFile_Click" runat="server">
</td>
</tr>
</form>
</table>
<span id=txtOutput style="font: 8pt verdana;" runat="server" />
</body>
</html> |