How can i download files like(.doc,.txt,.pdf,.gif) which are already uploaded to databse in asp.net using c#,plz help me regarding this
2 925
Welcome to TSDN. Please explain and provide more info. Thanks.
Hello rajnow...
I am assuming that you want to download a file that is stored in a table in a database, in, for example, an image column...
The solution is pretty intricate, downloading the file in chunks, but see code below (this uses the SQLHelper class, but you could quite comfortable write code to replace that as well (variables in $-signs need to be provided): -
System.Data.SqlClient.SqlConnection cn = null;
-
int offset = 0;
-
-
System.Data.SqlClient.SqlParameter[] pointerParams =
-
new System.Data.SqlClient.SqlParameter[2];
-
-
string selectSql = @"
-
SELECT @pointer = TEXTPTR(" + $fieldName$ + @"),
-
@length = DataLength(" + $fieldName$ + @")
-
FROM " + $tableName$ + @"
-
WHERE " + $whereClause$;
-
-
pointerParams[0] = new System.Data.SqlClient.SqlParameter("@pointer", SqlDbType.Binary, 16);
-
pointerParams[1] = new System.Data.SqlClient.SqlParameter("@length", SqlDbType.Int, 4);
-
pointerParams[0].Direction = ParameterDirection.Output;
-
pointerParams[1].Direction = ParameterDirection.Output;
-
-
DAL.SqlHelper.ExecuteNonQuery(
-
$connectionString$,
-
CommandType.Text,
-
selectSql,
-
pointerParams);
-
-
cn = new System.Data.SqlClient.SqlConnection($connectionString$);
-
cn.Open();
-
-
if (cn.State != ConnectionState.Open)
-
return null;
-
-
System.Data.SqlClient.SqlCommand cmdRead = new System.Data.SqlClient.SqlCommand(
-
"READTEXT " + $tableName$ + "." + $fieldName$ + @" @Pointer @Offset @Size HOLDLOCK", cn);
-
-
System.Data.SqlClient.SqlParameter pointerParam = cmdRead.Parameters.Add("@Pointer", SqlDbType.Binary, 16);
-
System.Data.SqlClient.SqlParameter offsetParam = cmdRead.Parameters.Add("@Offset", SqlDbType.Int);
-
System.Data.SqlClient.SqlParameter sizeParam = cmdRead.Parameters.Add("@Size", SqlDbType.Int);
-
pointerParam.Value = pointerParams[0].Value;
-
offsetParam.Value = 0;
-
-
System.Data.IDataReader reader;
-
-
byte[] buffer = new byte[System.Convert.ToInt32(pointerParams[1].Value)];
-
do
-
{
-
pointerParam.Value = pointerParams[0].Value;
-
if ((offset + $BufferChunkLength$) >= System.Convert.ToInt32(pointerParams[1].Value))
-
sizeParam.Value = System.Convert.ToInt32(pointerParams[1].Value) - offset;
-
else
-
sizeParam.Value = $BufferChunkLength$;
-
-
reader = cmdRead.ExecuteReader(CommandBehavior.SingleResult);
-
reader.Read();
-
reader.GetBytes(0, 0, buffer, offset, System.Convert.ToInt32(sizeParam.Value));
-
reader.Close();
-
offset += System.Convert.ToInt32(sizeParam.Value);
-
offsetParam.Value = offset;
-
-
} while (offset < Convert.ToInt32(pointerParams[1].Value));
-
-
return buffer;
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: m004202002 |
last post by:
I have recently visit a website where to download
a file ,I need to login then by clicking
http://www.abc.com/jj/Download.php?sID=e0992e5916
the file abc.exe start downloading .
How to code...
|
by: Luke StClair |
last post by:
Only marginally belonging in this newsgroup... but oh well.
I've just started writing in python, and I want to make the files
available on the web. So I did the standard <a...
|
by: sales |
last post by:
If you are having difficulty downloading large files, please check out
www.Downloads4Dialups.com. Mention this newsgroup in the "Special
Instructions" window on the Shipping Form, and receive a...
|
by: Bala |
last post by:
Hi
I am trying to download the PDF files from my webserver using ASP.Net.
All my files are stored at F Drive on webserver. Like this F:\Main
Folder\Sub Folder\Files\File1.pdf
I am...
|
by: just.starting |
last post by:
Hi,
My dot net client downloads files and checks for any new files time to
time. The server is apache2.0.53 server. So what happens is that my
file download thing works fine if I dont try to call...
|
by: just.starting |
last post by:
Hi,
My dot net client downloads files and checks for any new files time to
time. The server is apache2.0.53 server. So what happens is that my
file download thing works fine if I dont try to call...
|
by: just.starting |
last post by:
I am having problem while downloading files from an apache server2.0.53
with php4.3.10.While downloading some files it generally stops after
downloading some specific amount and then stops...
|
by: ginnisharma1 |
last post by:
Hi All,
I am very new to C language and I got really big assignment in my
work.I am wondering if anyone can help me.........I need to port
compiler from unix to windows and compiler is written...
|
by: Ehsan |
last post by:
I foundd this code in ASPN Python Cookbook for downloading files in
python but when it finished downloading files the files became
corrupted and didn't open, the files in internet havn't any...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |