Solved

FileStream and file upload

Posted on 2008-10-20
3
3,594 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

707 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