views:

33

answers:

2

I am currently learning C# during my studies and I am writing a small movie database application in it. I know its not good to save pictures (etc) inside the database, especially when adding movie covers that are rather big. But I don't want the files to just get saved in a folder as this creates a mess if more and more movies are added to the list.

Does anyone know a way to store the files in some sort of a container file (like covers.xxx). Then that container contains all covers in one big file, the files can then be retrieved with an address or the name.

Thanks :)

A: 

I can't see why storing the files as binary in the db is necessarily a bad idea.

However if it's definitely out then it sounds like you want a way to store a non-compressed compilation of files - basically a .zip that isn't compressed. You could achieve this for yourself by creating a file that is simply the data of the files you want appended together with some sort of unique header string in between them that you can split on when you read from the file. Ultimately this is simulating a basic file DB so I'm not sure what you'd accomplish but it's an idea.

Graphain
ZIP files can have no compression if you want them to have no compression.
icktoofay
Cool, well then you're at ZIP file versus DB, and I'm not sure what is gained by using the ZIP file
Graphain
he'll gain faster db as the db is not heavily messed with binary file rows. plus the smaller file size as the zip compresses.
VOX
@VOX Not saying .zip is necessarily worse but I can't see why it is better either. You'd probably have to decompress on every file read for instance if you do go for the smaller file size. The db should be fine if you put the binary stuff in its own table with a FK index to your main table - as it stands the OP will presumably have to query the db to get the correct filename within the zip anyway. Fortunately you can retrieve a file without decompressing the lot.
Graphain
hmm, i guess let him decide what best for him :P I still feel storing binary files in db is a bad idea. Wordpress, Blogger, every other great engines i know doesn't store files in their db.
VOX
+2  A: 

http://dotnetzip.codeplex.com/

Use above library and following code snippet.

 using (ZipFile zip = new ZipFile())
 {
     // add this map file into the "images" directory in the zip archive
     zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
     // add the report into a different directory in the archive
     zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
     zip.AddFile("ReadMe.txt");
     zip.Save("MyZipFile.zip");
 }
VOX
This would be nice to retrieve with too by the looks of it
Graphain