Hi,
I need to insert multiple files from front-end in the same datacolumn in DB using c#.
& also need to retrieve from DB to UI.
Please help me out.
My code is as follows... - string filePath = fDialog.FileName;
-
string[] fileNames = fDialog.FileNames;
-
string filename = System.IO.Path.GetFileName(filePath);
-
string ext = Path.GetExtension(filename);
-
byte[] FilesData=null;
-
List<byte> FileData = new List<byte>();
-
List<string> AllFiles = new List<string>();
-
-
for (int i = 0; i < fileNames.Length; i++)
-
{
-
AllFiles.Add(fileNames[i]);
-
}
-
foreach (string str in AllFiles)
-
{
-
FileStream fs = new FileStream(str, FileMode.Open, FileAccess.Read);
-
BinaryReader br = new BinaryReader(fs);
-
FilesData = br.ReadBytes((int)fs.Length);
-
-
-
br.Close();
-
fs.Close();
-
}
-
-
-
try
-
{
-
connection.Open();
-
string query = "insert into TableName(IDVERSION,FILENAME,FILE) values(@Idversion,@FileName,@File);commit;";
-
command = new DB2Command(query, connection);
-
command.Parameters.Add("@Idversion", DB2Type.Integer).Value = 0012013;
-
command.Parameters.Add("@FileName", DB2Type.VarChar).Value = AllFiles.ToString();
-
command.Parameters.Add("@File", DB2Type.Binary).Value = FilesData;
-
command.ExecuteNonQuery();
-
}
-
catch (Exception)
-
{ }
-
finally
-
{
-
connection.Close();
-
}
1 2188 -
private void btnUpload_Click(object sender, EventArgs e)
-
{
-
string filePath = fDialog.FileName;
-
string[] fileNames = fDialog.FileNames;
-
string filename = System.IO.Path.GetFileName(filePath);
-
string ext = Path.GetExtension(filename);
-
byte[] FilesData=null;
-
int FileSize = 0;
-
int size=0;
-
-
List<string> AllFiles = new List<string>();
-
-
for (int i = 0; i < fileNames.Length; i++)
-
{
-
if (i == fileNames.Length)
-
{
-
strin.Append(filename[i]);
-
-
}
-
else
-
{
-
strin.Append(filename[i]);
-
strin.Append(",");
-
}
-
//AllFiles.Add(fileNames[i]);
-
-
//foreach (string str in AllFiles)
-
//{
-
FileStream fs = new FileStream(fileNames[i], FileMode.Open, FileAccess.Read);
-
BinaryReader br = new BinaryReader(fs);
-
-
//FilesData = br.ReadBytes((int)fs.Length);
-
byte[] fileContent = br.ReadBytes((int)fs.Length);
-
FileSize = fileContent.Length;
-
size = size + FileSize;
-
br.Close();
-
fs.Close();
-
//}
-
}
-
-
byte[] sizebyte =BitConverter.GetBytes(size);
-
-
-
-
try
-
{
-
connection.Open();
-
string query = "insert into tblFiles(IDVERSION,FILENAME,FILE) values(@Idversion,@FileName,@File);";
-
command = new DB2Command(query, connection);
-
command.Parameters.Add("@Idversion", DB2Type.Integer).Value =147822 ;
-
command.Parameters.Add("@FileName", DB2Type.VarChar).Value = strin.ToString();
-
command.Parameters.Add("@File", DB2Type.Binary).Value = sizebyte;
-
command.ExecuteNonQuery();
-
}
-
catch (Exception)
-
{ }
-
finally
-
{
-
connection.Close();
-
}
-
-
-
-
}
-
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bola |
last post by:
Is anyone know how I can store Word Docs and PDF's in database, and how I
can make link for visitor to download these files
|
by: Roshan James |
last post by:
Hi,
I'm creating an application which requires to store multiple file
attachments in SQL Server Database from a windows form.
I am able to store the files and retreive the files from the...
|
by: grzybek |
last post by:
Hi,
I have question about techniques of using files
in SQL Server in Web Application.
Assuming that I send files from my Web App ( client )
to server and located these files on hard disk ( on...
|
by: Nicolas |
last post by:
How to store multiple files in only one sql blod field in sql database
Like I got a record for a house:
ID
Name
addresss
price
attachments
The field "attachments" may contains documents...
|
by: akashkhasgiwala |
last post by:
i am developing i web application in which every user will have an Xml File containing mostly text and date/time stamps
this application will use MySql for storing data
so pl tell me if i can STORE...
|
by: lyealain |
last post by:
how to store many files in one database fields?? i manage to store one file into database field.. but fail to store many files.....
how should i do that>> one database field for many files name.....
|
by: poopsy |
last post by:
hello all,
i am developing a web application for my final year project where i will be able to download and upload files(more specifically, it will be papers and articles, mostly pdf files) from the...
|
by: MoroccoIT |
last post by:
Greetings -
I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
|
by: crazykreize |
last post by:
I want to know how to store text files format (.txt) in the SQL Server 2005.
|
by: Deepa Avudiappa |
last post by:
We have designed a basic text editor using GTK+ in Ubuntu.
We are supposed to store text files within a database(postgreSQL) which can be retrieved, viewed on our editor, modified using the options...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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: 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...
| | |