R
Ryan Taylor
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&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 ©2004, Acceleron Compliance Systems
</td>
</tr>
</table>
</div>
</body>
</HTML>
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&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 ©2004, Acceleron Compliance Systems
</td>
</tr>
</table>
</div>
</body>
</HTML>