Solved

FileStream and file upload

Posted on 2008-10-20
3
3,560 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
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…

821 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