Reply to topic
Uploading files and adding to Access database
meadean


Joined: 03 Jun 2007
Posts: 1
Reply with quote
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

Code:
<% @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 &quot;Name on Server&quot; box</em></li>
  <li><em>4) Click &quot;Upload&quot; 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>
rj


Joined: 17 Jun 2004
Posts: 34
Reply with quote
I did some checking here and I didn't find any specific articles that reference how do what you want. You should just be able to upload the file, set the upload path with the filename as a variable and then use an insert statement to place the recordset into the database. I am not a programmer by heart so I can't give you the code version of that.
Uploading files and adding to Access database
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic