How to Download A file stored in SQL DB in Binary Format

后端 未结 3 1877
春和景丽
春和景丽 2020-12-19 09:31

I am simply storing uploaded file into a binary field in SQL Server but I also need to allow users to download it with Asp.NET. How can I do that ?

Thanks in advance

3条回答
  •  半阙折子戏
    2020-12-19 10:04

    Read the data into a filestream object with the appropriate extension tacked on to it, and have the user download the resulting file.

    You'll want to use the System.IO BinaryWriter object on the filestream to create the file...something like this:

    FileStream fs = new FileStream("thisfile.bin", FileMode.Create);
    binWriter= new BinaryWriter(fs);    
    
    binWriter.Write(varHoldingSqlRetrievedBinaryData);
    

提交回复
热议问题