473,378 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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="dDwtMTY4MjY1MzA1Mjt0PDtsPGk8Mz47PjtsPHQ8O2w 8aTwzPjtpPDU+Oz47bDx0PHA8c
DxsPFRleHQ7PjtsPHZlcnNpb246IDAuNDs+Pjs+Ozs+O3Q8cDx wPGw8VGV4dDs+O2w8TG9nZ2VkI
GluIGFzIFJlc3BvbmRpbmdBZG1pblw8YnJcPlJlc3BvbmRpbmc gT3JnYW5pemF0aW9uIEFkbWlua
XN0cmF0b3I7Pj47Pjs7Pjs+Pjs+Pjs+k8oUXBcNrY4GyfjocrI X5+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>

Nov 18 '05 #1
2 1809
add a Response.End() after the flush

-- bruce (sqlwork.com)
"Ryan Taylor" <rt*****@stgeorgeconsulting.com> wrote in message
news:e0**************@TK2MSFTNGP15.phx.gbl...
| 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="dDwtMTY4MjY1MzA1Mjt0PDtsPGk8Mz47PjtsPHQ8O2w 8aTwzPjtpPDU+Oz47bDx0PHA8c
|
DxsPFRleHQ7PjtsPHZlcnNpb246IDAuNDs+Pjs+Ozs+O3Q8cDx wPGw8VGV4dDs+O2w8TG9nZ2VkI
|
GluIGFzIFJlc3BvbmRpbmdBZG1pblw8YnJcPlJlc3BvbmRpbmc gT3JnYW5pemF0aW9uIEFkbWlua
| XN0cmF0b3I7Pj47Pjs7Pjs+Pjs+Pjs+k8oUXBcNrY4GyfjocrI X5+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>
|
|
|
Nov 18 '05 #2
Awesome.
Thanks Bruce.

Ryan Taylor
Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Aaron | last post by:
On my website I have a dynamic link(aspx) to this file 0AX120S.jpg(privacy protection). When a visitor clicks on the link I want them to see my_vacation_pic.jpg (fetch realname from database) is...
1
by: BW | last post by:
I am creating an upload/download function for an extranet site. Files will be uploaded to directory based upon the users login and associated project. The function works as long as I use "c:\Temp"...
6
by: Paul | last post by:
Hi there, When adding a "File Field" HTML control to an aspx page to facilitate file uploading, the following occurs: 1. You select a file that is larger than the allowed size limit. 2. Once...
5
by: Seok Bee | last post by:
Dear Experts, I currently trying to use the FileUpload control from asp.net 2.0 to upload files. The uploading of the file I would like to store it in the Access Database. Unfortunately, I've no...
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
1
by: Brett Kelly | last post by:
Ok, I know this sounds odd. Let me explain further. I have an ASP.net page (w/ C# code behind) that, when given a session variable containing the path to a local file, will attempt to start the...
6
by: =?Utf-8?B?U2NvdHQgVHJpY2s=?= | last post by:
I followed the instructions from MSDN for Webclient UploadFile and I get an error: Could not find file 'C:\testfile.xls'. If I add the file (c:\testfile.xls) to the server I do not get the error...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.