473,320 Members | 2,193 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,320 software developers and data experts.

Downloaded file is corrupt

16
Expand|Select|Wrap|Line Numbers
  1. string SQL = "SELECT FileName,FileSize,ContentType,FileData FROM FileTable WHERE FileID = '" + FileID + "'";
  2.         SqlConnection con = Connection.GetConnection();
  3.         SqlCommand cmd = new SqlCommand();
  4.         DataTable dt = new DataTable();
  5.         SqlDataAdapter da = new SqlDataAdapter(SQL, con);
  6.         cmd.CommandType = CommandType.Text;
  7.         cmd.Connection = con;
  8.         da.Fill(dt);
  9.         Byte[] bytes = System.Text.Encoding.Unicode.GetBytes(dt.Rows[0][3].ToString());
  10.         Response.Buffer = true;
  11.         Response.Charset = "";
  12.         Response.Cache.SetCacheability(HttpCacheability.NoCache);
  13.         Response.ContentType = dt.Rows[0][2].ToString();
  14.         Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0][0].ToString());
  15.         Response.BinaryWrite(bytes);
  16.         Response.Flush();
  17.         Response.End();
  18.  
Feb 8 '12 #1
2 2156
PsychoCoder
465 Expert Mod 256MB
It's nice that you've provided code, and put it in code tags even, but you've given no information on what the issue is, any error messages you're getting or anything.

You stand a better chance of getting help if you edit your post and tell us what the issue is.
Feb 9 '12 #2
Newface
16
I am trying download any specific file from database through this code.the issue is after execution of this code file is downloaded but if click open,it shows "the file is corrupt and con not be opended"


@Richard McCutchen
Feb 9 '12 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
4
by: SS | last post by:
We built an MSI file to deploy a .net app to the workstation. We created an HTML page that has a link to the MSI file. On a very sporadic basis, when the MSI is run we get the following message:...
2
by: ntm | last post by:
I am using the following ASPC.VB code to download a text file: Response.Clear() Response.ContentType = "ignore/this" ' arbitrary Response.AddHeader("Content-Disposition",...
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...
1
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm running this code to open a stream as pdf file: Response.ContentType = "application/pdf"; try { mystream = someStream....; byte myfile = mystream.ReadBytes((int)someStreamLenght);...
1
by: Rajaaa | last post by:
Hello Everyone, While i'm downloading a file it will correctly downloaded but contents of .doc file is doesn't display,but if i open .txt file that content has been displaying. <?php...
1
by: mekman | last post by:
I wrote a script for downloading files. When the file has been downloaded it is a couple of 100 bytes bigger than it is on the server. The script looks like this: $file = '../dlf/Volume.exe';...
0
by: makinha | last post by:
Hello All, I can use WebClient.DownloadFile Method to download target file from the website, like WebClient.DownloadFile("http://www.abc.com/a.pdf", "D:\a.pdf") but how can I verify the...
2
by: emphyrio | last post by:
Hi, I am new to programming in vb. net. I have this problem: I created a form with a datagrid. I can add records and then save them to a XML file, using this code on the click event of a button...
4
by: Tinus | last post by:
Hi I have a php code that uploads a file to mysql db then I detrmine the id of the last inserted file and download the file .e user is asked if he wants to save the file and then asked for te...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.