How to upload a photo to MS SQL using C# ASP.NET

Hey guys,

I would like to use my C# application to store images.

I suppose the best way is to make it so the image gets moved to the \\Images folder for the application and then the Database stores the file path? Or would it be better to store the image in the database itself?

I have table RoomPhoto with fields:
TenancyAgreement_ID (FK from TenancyAgreement table)

What is the best way to do this and how would I do it?

Thanks in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ephraim WangoyaCommented:

its better to store the image outside the database and store the file path in the DB
If you want to treat the \\images folder as a cache for the database to save a trip to the db then a copy placed there is fine. However, if you want to insure that the image is the image placed into the database then just push the image to the database in a background thread.
The solution depends on whether you want the user to be able to view the images without the application running also, if so then use \\images

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ephraim WangoyaCommented:

Also look at the new FILESTREAM feature in SQL 2008, its meant for exactly what you are trying to do
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

bpsp10Author Commented:
Ok thanks for the advice..... now the hard bit....

How would I go about doing this? Any examples for code?

Here is some background and some sample code
teodor bircaCommented:
I recommend you to read this:
I don't think is a good practice to store the photo inside database.
Guy Hengel [angelIII / a3]Billing EngineerCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.