0

I am currently having to stream multiple files to database and retrieve. The challenge is the number of files to stream is unknown, the file names are unknown and there is only one field in database to store all the files! The good thing is the location of the files to stream is fixed.

Eg. 
Location to stream from : c:\Temp\FilesToStreamFolder 
Current files (the number of files is unknown and names can differ too)
test.dat
background.jpeg
banner.gif
otherdata.dat

I would like to stream all these files to database (one data field) and retrieve the files back as an when required, with appropriate names?

Hope I have explained well. Any thoughts, ideas etc from you guys is greatly appreciated. Thank you.

2
  • what other fields do you have beside your data field(BLOB?). Do you have Fields for file names and lengths? Commented Jul 12, 2013 at 11:13
  • Hi Marco, Thanks for your response. Unfortunately at the moment I only have one field in the database. There are no other fields in the database to store file names. Commented Jul 12, 2013 at 11:15

1 Answer 1

1

I will suggest to convert a file to byte arrays first. Then record its Length and Name in datatable. Get byte array of another file and append it to the previous array and record its length and name in datatable. Continue the same procedure for all the files. Update the database with your byte array to store all files. Store your datatable as an XML file in system.

Whenever you need to get the files back, read the database field. Read your XML file. Split the array based on the File length from XML file. Use the corresponding name. You can optionally save the XML file data in database as well, if its possible. I hope you are looking for same thing.

Hope it helps.

Sign up to request clarification or add additional context in comments.

4 Comments

Can there be any foolproof method to prefix the datatable along with the bytearray so that no dependency is kept on the client?
Then you must store the file also to database.
Unfortunately there is only one field to store the files in the database and I do not have an option to change the database. XML file suggestion is good however it can be tampered with.
dataTable.WriteXml("..../Sample.xml"); can be used if XML file is also an option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.