Search code examples
c#sql-server.net-corefilestreamfiletable

.NET core support for SqlFileStream or any alternative way to get a filestream out of SQL Server using C#?


I noticed SqlFileStream is not supported in .NET Core. But then read it might be available in 3.0? I have some sample code in .NET classic.

Basically I am trying to get the data somehow from a SQL command in C# to a filestream that I can copy to another folder location.


Solution

  • There are two APIs for Filestream. There's a Win32 handle-based API, which isn't available in .NET Core, and the ordinary TSQL API, which is. A Filestream file appears to the TSQL API as varbinary(max) column, and can be accessed like any other varbinary(max) column.

    In particular you can use SqlClient Streaming for streaming access to varbinary(max) data in SQL Server, whether it's stored in the file system (FileStream/FileTable), or inside your SQL Server database files. In fact the sample on that doc page shows you how to stream a varbinary(max) column into a local file.