Solved

FileStream and file upload

Posted on 2008-10-20
3
3,546 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
ID: 22765054
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
ID: 22765365
0
 
LVL 2

Accepted Solution

by:
johnhumenik earned 55 total points
ID: 22773421
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Resolve Dependency Issues 4 44
Error in query expression 3 35
Remove greater than sign 3 42
VB.NET Repostiory Pattern 7 8
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

23 Experts available now in Live!

Get 1:1 Help Now