I have a small web app that publishes files to a SQL database. I just
noticed this morning that 2 conditions exist that I need help with.
1.) Any file that can be open with NotePad have the HTML for the web
page appended to the document when it's received. Example...
This line was entered in the *.txt file prior to upload. Everything
below this was added when retrieving from SQL.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Untitled Page
</title>
<link href="App_Theme s/j
End Example
Upload Code:
VaultGridView.S electedIndex = -1;
strConnection =
ConfigurationMa nager.Connectio nStrings["DocumentVaultC onnectionString "].ConnectionStri ng;
dbConn = new SqlConnection(s trConnection);
dbConn.Open();
dcmd = new SqlCommand();
dcmd.CommandTex t = "INSERT INTO [DocumentVault].[dbo].
[tblVault] " +
"([tID] " +
",[FileName] " +
",[Filesize] " +
",[FileData] " +
",[uBy] " +
",[uDate]) " +
"VALUES " +
"(@tID " +
",@FileName " +
",@Filesize " +
",@FileData " +
",@uBy " +
",@uDate)";
dcmd.Parameters .Add(new SqlParameter("t ID",
TumblersGridVie w.SelectedValue ));
dcmd.Parameters .Add(new SqlParameter("F ilename",
FileUpload1.Fil eName));
dcmd.Parameters .Add(new SqlParameter("F ilesize",
FileUpload1.Pos tedFile.Content Length));
dcmd.Parameters .Add(new SqlParameter("F ileData",
FileUpload1.Fil eBytes));
dcmd.Parameters .Add(new SqlParameter("u By",
Session["UserID"].ToString()));
dcmd.Parameters .Add(new SqlParameter("u Date",
DateTime.Now.Da te));
dcmd.Connection = dbConn;
dcmd.ExecuteNon Query();
VaultGridView.D ataBind();
Download Code:
strConnection =
ConfigurationMa nager.Connectio nStrings["DocumentVaultC onnectionString "].ConnectionStri ng;
dbConn = new SqlConnection(s trConnection);
dbConn.Open();
dcmd = new SqlCommand();
dcmd.CommandTex t = "SELECT [FileName], [FileData] " +
"FROM [DocumentVault].[dbo].[tblVault] " +
"WHERE([vID] = @vID)";
dcmd.Parameters .Add(new SqlParameter("v ID",
VaultGridView.S electedValue));
dcmd.Connection = dbConn;
SqlDataReader dr = dcmd.ExecuteRea der();
dr.Read();
Response.Clear( );
Response.Conten tType = "applicatio n/x-unknown";
Response.Append Header("Content-Disposition",
"attachment ; filename=\"" + dr["FileName"] +
"\"");
Response.Binary Write((byte[])dr["FileData"]);
dbConn.Close();
VaultGridView.S electedIndex = -1;
2.) All Office 2007 documents when retrieved open as corrupt.
Everything that I've found so far shows that Response.WriteB inary is
the right directrion. If it's not, I'm sure that there's someone out
there that can give me the right path to take.
Thanks
noticed this morning that 2 conditions exist that I need help with.
1.) Any file that can be open with NotePad have the HTML for the web
page appended to the document when it's received. Example...
This line was entered in the *.txt file prior to upload. Everything
below this was added when retrieving from SQL.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Untitled Page
</title>
<link href="App_Theme s/j
End Example
Upload Code:
VaultGridView.S electedIndex = -1;
strConnection =
ConfigurationMa nager.Connectio nStrings["DocumentVaultC onnectionString "].ConnectionStri ng;
dbConn = new SqlConnection(s trConnection);
dbConn.Open();
dcmd = new SqlCommand();
dcmd.CommandTex t = "INSERT INTO [DocumentVault].[dbo].
[tblVault] " +
"([tID] " +
",[FileName] " +
",[Filesize] " +
",[FileData] " +
",[uBy] " +
",[uDate]) " +
"VALUES " +
"(@tID " +
",@FileName " +
",@Filesize " +
",@FileData " +
",@uBy " +
",@uDate)";
dcmd.Parameters .Add(new SqlParameter("t ID",
TumblersGridVie w.SelectedValue ));
dcmd.Parameters .Add(new SqlParameter("F ilename",
FileUpload1.Fil eName));
dcmd.Parameters .Add(new SqlParameter("F ilesize",
FileUpload1.Pos tedFile.Content Length));
dcmd.Parameters .Add(new SqlParameter("F ileData",
FileUpload1.Fil eBytes));
dcmd.Parameters .Add(new SqlParameter("u By",
Session["UserID"].ToString()));
dcmd.Parameters .Add(new SqlParameter("u Date",
DateTime.Now.Da te));
dcmd.Connection = dbConn;
dcmd.ExecuteNon Query();
VaultGridView.D ataBind();
Download Code:
strConnection =
ConfigurationMa nager.Connectio nStrings["DocumentVaultC onnectionString "].ConnectionStri ng;
dbConn = new SqlConnection(s trConnection);
dbConn.Open();
dcmd = new SqlCommand();
dcmd.CommandTex t = "SELECT [FileName], [FileData] " +
"FROM [DocumentVault].[dbo].[tblVault] " +
"WHERE([vID] = @vID)";
dcmd.Parameters .Add(new SqlParameter("v ID",
VaultGridView.S electedValue));
dcmd.Connection = dbConn;
SqlDataReader dr = dcmd.ExecuteRea der();
dr.Read();
Response.Clear( );
Response.Conten tType = "applicatio n/x-unknown";
Response.Append Header("Content-Disposition",
"attachment ; filename=\"" + dr["FileName"] +
"\"");
Response.Binary Write((byte[])dr["FileData"]);
dbConn.Close();
VaultGridView.S electedIndex = -1;
2.) All Office 2007 documents when retrieved open as corrupt.
Everything that I've found so far shows that Response.WriteB inary is
the right directrion. If it's not, I'm sure that there's someone out
there that can give me the right path to take.
Thanks
Comment