Solved

FileStream and file upload

Posted on 2008-10-20
3
3,529 Views
Last Modified: 2009-12-16
I wish to be able to upload files to the server via a file upload control on a ASP.NET Wep application.

Allowed files, any (doc, pdf, etc..)

I wish to use filestream to achieve it by converting the file to binary and saving it into a table/database.

I wish to be able to download the file on a later stage. Be it pdf, exe, doc, txt,.watever

Questions:
1) Is it doable/possible?
2) Are there any easy to understand tutorials I can look at?  As my google did not really return the ones I am looking for or basically too hard for me to understand.
3) Need some understanding on upload and download before proceeding.

Any help will be much appreciated.


0
Comment
Question by:Joshscorp
3 Comments
 
LVL 18

Assisted Solution

by:philipjonathan
philipjonathan earned 35 total points
Comment Utility
Have you checked these articles, they have quite a good walkthrough:
http://msdn.microsoft.com/en-us/library/aa479405.aspx
http://www.codeproject.com/KB/aspnet/fileupload.aspx
0
 
LVL 15

Assisted Solution

by:angus_young_acdc
angus_young_acdc earned 35 total points
Comment Utility
0
 
LVL 2

Accepted Solution

by:
johnhumenik earned 55 total points
Comment Utility
First off, from experience the performance hit is terrible.  Optimizing the database to handle binary files works, but you will take a hugh hit on performance.  Saving the file to a network share where all the users have access and storing that path (\\server\fileshare) is the best way.  

But if you want to go with uploading data using LINQ, which can be easily translated to SQL Data types also:

            byte[] img = null;
            if (filUploadPicture.HasFile)
            {
                img = new byte[filUploadPicture.PostedFile.ContentLength];
                filUploadPicture.PostedFile.InputStream.Read(img, 0, img.Length);

                using (DBDataContext database = new DBDataContext())
                {
                    Picture newPicture = new Picture();
                    newPicture.Name = "Test Image";
                    newPicture.Description = "Test Description";
                    newPicture.Image = new System.Data.Linq.Binary(img);

                    FileIO thumb = new FileIO();
                    byte[] thumbNail = thumb.ResizePicture(filUploadPicture.PostedFile.FileName, 120, 80);

                    newPicture.Thumbnail = thumbNail;
                    newPicture.IsActive = true;

                    database.Pictures.InsertOnSubmit(newPicture);
                    database.SubmitChanges();
                }
            }
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now