File upload/download from database. Download appends aspx page to end of file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Ryan Taylor (rtaylor_at_stgeorgeconsulting.com)
Date: 11/10/04


Date: Wed, 10 Nov 2004 14:59:42 -0500

Hello.

I am trying to upload a file and save it in a Sql Server 2000 database. This
seems to be working fine. However, when I download the file from SQL Server,
it appears that the page that is downloading this file is being appended to
the end of the file. So I am accidently modifiying every file that is placed
in the database. What follows is my code for uploading and downloading a
file, minus the sql code to insert/retrieve the data into/from the database.
Does anyone see what might be wrong? Thanks in advance.

// uploading a file
HttpPostedFile file = btnAttachFile.PostedFile;
string fileName = System.IO.Path.GetFileName(file.FileName);
string mimeType = file.ContentType;
int fileSize = file.ContentLength;
byte[] fileData = new byte[fileSize];
file.InputStream.Read(fileData, 0, fileSize);

int questionId = Convert.ToInt32(Request.Params["qId"]);
int sessionId = Convert.ToInt32(Request.Params["sId"]);
string btnAttach = Request.Params["btnAttach"];

if(QstnrSql.UpdateAttachment(authUser, questionId, sessionId, fileName,
mimeType, ref fileData))
{
 // success
}

// downloading a file
byte[] buffer = null;
string attachmentFileName = "";
string attachmentMimeType = "";
if(QstnrSql.DownloadAttachment(authUser, questionId, sessionId, out buffer,
out attachmentFileName, out attachmentMimeType))
{
 // Convert the content to application/pdf
 Response.Clear();
 Response.ContentType = attachmentMimeType;
 Response.AppendHeader("Content-Disposition", "Attachment; Filename=\"" +
attachmentFileName +"\"");
 Response.BinaryWrite(buffer);
 Response.Flush();
}

// orginal file orginalfile.txt
hello

//downloaded file originalfile2.txt
hello
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>ACMS: View Attachment</title>
  <LINK href="../AcmsStyles.css" type="text/css" rel="stylesheet">
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="C#" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
 </HEAD>
 <body leftMargin="0" topMargin="0" ms_positioning="FlowLayout"
marginheight="0" marginwidth="0">

<script language="JavaScript1.2"
vqm_id="/acms/MenuScripts/ResOrgAdmin/ResOrgAdminData.js"
type="text/javascript">

 vqm__notice='Visual QuickMenu Pro, (c) 2004 OpenCube Inc., All Rights
Reserved, Visit - www.opencube.com';

 vqm__codebase='/acms/MenuScripts/ResOrgAdmin/';
 vqm__database='/acms/';

</script>
<script language="JavaScript1.2"
src="/acms/MenuScripts/ResOrgAdmin/ResOrgAdminData.js"
type="text/javascript"></script>
<script language="JavaScript1.2"
src="/acms/MenuScripts/ResOrgAdmin/tdqm_loader.js"
type="text/javascript"></script>
  <div class="outterDiv">
   <table class="outterTable" cellSpacing="0" cellPadding="0">
    <tr>
     <td class="headerCell">
<table id="tblHeader" cellspacing="0" cellpadding="0" class="headerTable">
 <tr>
  <td colspan="3" class="headerBarTop">
  </td>
 </tr>
 <tr>
  <td colspan="3" class="headerBarCenter"></td>
 </tr>
 <tr>
  <td colspan="3" class="headerBarBottom"></td>
 </tr>
 <tr>
  <td class="headerImgCell" rowspan="3">
   <img id="header_logo" class="headerLogoImg" src="../images/logo.jpg"
alt="Logo" border="0" />
  </td>
  <td class="headerAppTitleCell" rowspan="3">
   <div class="headerAppTitle" id="appTitle">Acceleron Compliance Management
System</div>
  </td>
  <td class="headerStatusCell">
   <span id="header_lblVersion" class="headerStatus">version: 0.4</span>
  </td>
 </tr>
 <tr>
  <td class="headerStatusCell">
   <span id="header_lblStatus" class="headerStatus">Logged in as
RespondingAdmin<br>Responding Organization Administrator</span></td>
 </tr>
 <tr>
  <td class="headerStatusCell">
   <a id="header_lnkLogout" class="headerStatus"
href="../logout.aspx">logout</a></td>
 </tr>
 <tr>
  <td colspan="3" class="headerBarTop"></td>
 </tr>
 <TR>
  <TD class="headerBarCenter" colSpan="3"></TD>
 </TR>
 <TR>
  <TD class="headerBarBottom" colSpan="3"></TD>
 </TR>
</table>
</td>
    </tr>
    <tr>
     <td class="innerTableCell">
      <table class="innerTable" cellSpacing="0" cellPadding="0">
       <tr>
        <td class="navbarCell">
<script id="vqp_generate_mainitems"
language="javascript1.2">generate_mainitems()</script></td>
        <td class="gutterCell"></td>
        <td class="contentCell">
         <form name="frmViewAttach" method="post"
action="ViewAttach.aspx?sId=32&amp;qId=1128" id="frmViewAttach">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTY4MjY1MzA1Mjt0PDtsPGk8Mz47PjtsPHQ8O2w8aTwzPjtpPDU+Oz47bDx0PHA8c
DxsPFRleHQ7PjtsPHZlcnNpb246IDAuNDs+Pjs+Ozs+O3Q8cDxwPGw8VGV4dDs+O2w8TG9nZ2VkI
GluIGFzIFJlc3BvbmRpbmdBZG1pblw8YnJcPlJlc3BvbmRpbmcgT3JnYW5pemF0aW9uIEFkbWlua
XN0cmF0b3I7Pj47Pjs7Pjs+Pjs+Pjs+k8oUXBcNrY4GyfjocrIX5+gh4O0=" />

          View Attachment
         </form>
        </td>
       </tr>
      </table>
     </td>
    </tr>
    <tr>
     <td class="footerCell">
Copyright &copy;2004, Acceleron Compliance Systems
</td>
    </tr>
   </table>
  </div>
 </body>
</HTML>



Relevant Pages

  • Re: viewing differences between 2 dbs (dev and production)
    ... You can try quasi-freeware (requires a downloading a new key every 60 days, ... click on Tools => SQL Server => Compare. ... * Select the databases to compare in the left and right pane. ... create scripts to actually sync one database to another (at least I haven't seen ...
    (microsoft.public.sqlserver.programming)
  • Re: ASP.NET with SQL image type for up/down...
    ... the contents of a binary in/out of a database table. ... SQL Server MVP ... > I've written code web-based uploading and downloading. ...
    (microsoft.public.sqlserver.programming)
  • Re: reading a big file
    ... sense to put the growing file into a database and write reports out of ... the database that extract the needed data. ... > The problem is that if I just openthe file and verify each line to see if ... > line means downloading the whole content of the file on my computer, ...
    (perl.beginners)
  • Re: Database design pattern question
    ... That is the problem that I really need to be able to have multiple copies of the databases being updated in parallel and to have the ability to synchronise them later. ... Maintain a transaction log and "replay" the transaction log for each copy of the database into the other databases.. ... If you go this route consider updating a central database as the first step and then downloading the central database to each of your local databases. ...
    (comp.databases)
  • Security settings for downloaded databases
    ... which means I'm constantly downloading databases ... from the Internet in order to grade and/or troubleshoot them: ... database files per week, minimum. ... database before I'm allowed to work with it. ...
    (comp.databases.ms-access)