سؤال

I have a sql server database that stores txt files in a varbinary column. I have a gridview controller (C#) that lists the files that are stored. What I would like to have happen is this: if a two or more files are selected from the gridview, the app or the database (doesnt matter to me) will concatentate all of the selected files content into one file that the user can download.

so if file one is a text file that contains the word "Hello" and File two is a text file the contains the word "world", the application will read content from both and create a new test file that contains "Hello World"

all suggestions welcome.

هل كانت مفيدة؟

المحلول

One way you could accomplish this is by having the query concatenate the data for you and create the file from that.

Such as,

select convert(varchar(1024), varbinaryA) + convert(varchar(1024), varbinaryB) from A_Table

نصائح أخرى

Your subject reads "two binary files" but the example you gave was "two text files". Those are two completely different things. Concatenating text files is easy and straightforward. You can use something like:

string firstFile = System.IO.File.ReadAllText("myfile1.txt");
string secondFile = System.IO.File.ReadAllText("myfile2.txt");

and then return the concatenated result firstFile + " " + secondFile to the user.

However, for binary files, if you concatenate them, they will no longer work. For example, the concatenation of firstFile.exe and secondFile.dll is not useful for anything. If you want to offer your users a single download for binary files, I suggest adding them to one compressed file (e.g. Zip file) and offer that file as a download. Your users can then extract the files and use them.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top