将文件(图片、音乐、电影)保存在容器文件中

发布于 2024-09-08 07:56:16 字数 211 浏览 2 评论 0原文

我目前正在学习C#,正在用它编写一个小型电影数据库应用程序。我知道将图片(等)保存在数据库中并不好,尤其是在添加相当大的电影封面时。但我不希望文件只是保存在文件夹中,因为如果将越来越多的电影添加到列表中,这会造成混乱。

有谁知道如何将文件存储在某种容器文件中(例如covers.xxx)。然后该容器将所有封面包含在一个大文件中,然后可以使用地址或名称检索这些文件。

谢谢 :)

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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£冰雨忧蓝° 2024-09-15 07:56:16

http://dotnetzip.codeplex.com/

使用上述库和以下代码片段。

 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");
 }

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");
 }
沫尐诺 2024-09-15 07:56:16

我不明白为什么将文件作为二进制存储在数据库中必然是一个坏主意。

然而,如果它确实已经出来了,那么听起来您想要一种存储非压缩文件编译的方法 - 基本上是一个未压缩的 .zip。您可以通过创建一个文件来自己实现此目的,该文件只是您想要附加在一起的文件的数据以及它们之间的某种唯一标头字符串,您可以在从文件中读取时将其拆分。最终,这是模拟一个基本文件数据库,所以我不确定你会完成什么,但这是一个想法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文