How to save file in SQL Server database if have file path?

后端 未结 5 2265
生来不讨喜
生来不讨喜 2020-12-15 00:16

I am building some C# desktop application and I need to save file into database. I have come up with some file chooser which give me correct path of the file. Now I have que

5条回答
  •  情歌与酒
    2020-12-15 01:09

    It really depends on the type and size of the file. If it's a text file, then you could use File.ReadAllText() to get a string that you can save in your database.

    If it's not a text file, then you could use File.ReadAllBytes() to get the file's binary data, and then save that to your database.

    Be careful though, databases are not a great way to store heavy files (you'll run into some performance issues).

提交回复
热议问题