Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guy!

I have some doubt in sql server and c#. I just wanted to know that Can we store Files( Word, Excel, Powerpoint, pdf) in Sql server 2008 OR we can store only the FilePath (File destination in particular harddrive)? I have learned from internet that we can store files in sql server but only in binary format is it true?

Please Help me Thanks!!
Posted

You can store any data in SQL server, if you need to - you don't *have* to store them as Binary as VARCHAR(MAX) will accept up to 2GB of data, but it is probably a good idea to do so anyway, as PDF files (and some versions of Word and excel files) are binary data anyway, and may not work if stored in a text field. But that's ok - binary isn't a problem, because all files are stored on your HDD in binary anyway!

Don't forget that when you send it back to the user as a download, you will just provide the file name and the data - it will be saved at the other end and all will be fine.
 
Share this answer
 
Comments
Nikhil@123 13-Apr-13 3:23am    
Thanks for Replying Sir!!
OriginalGriff 13-Apr-13 3:30am    
You're welcome!
 
Share this answer
 
Actually all files are in binary format. There is nothing else.
But I suggest you not to store the file in the database itself. It can grow really large, and in most cases you will gain nothing with it. There is a feature of Sql Server called FILESTREAM[^]. It has little to do directly with the filestreams from .net for example. This feature enables you to have all pros of of storing files in the database, and the files you store are really managed by sql server (you have backup and so on), but they are not stored inside the database, but on the filesystem. And you have several ways to access them, there is even a share you can use if you want remote access. The major advantage of it is that you don't need to put the huge load on the sql server that arises during such operations.
Of course, you have means to deal with them from c# too.
Please see following articles: How Do I: Use SQL File Stream[^]
http://blogs.microsoft.co.il/blogs/bursteg/archive/2008/05/12/ado-net-entity-framework-support-filestream.aspx[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900