Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to up load a pdf file in data base and show on page through a link control
Posted

Here is the solution

HttpPostedFile file = fileImage.PostedFile;
byte[] bytPDF = new byte[file.ContentLength];
Stream objStream;
objStream = file.InputStream;
objStream.Read(bytPDF , 0, file.ContentLength);
string fileName = file.FileName.Trim();


After that you can save the byte into the DB
 
Share this answer
 
Comments
Ankur\m/ 22-Apr-11 1:49am    
Why do you recommend storing the file in the database? Why not store it directly on the disk.
Saving and retrieving files from database will require extra overhead which is not at all required here.
Sandeep Mewara 22-Apr-11 2:08am    
Chill Ankur, OP asked to save file in DB.

What you say is another alternative for sure but has it's own pros-cons that I am sure you know too. :)
nit_singh 22-Apr-11 2:13am    
Yes sandeep, you are right. Thanks for your vote.
Ankur\m/ 22-Apr-11 2:15am    
Oh, I missed that part. Read the subject and then read the content too quickly.

What you say is another alternative for sure but has it's own pros-cons that I am sure you know too.
I do and in this case my recommendation would be to store it on the disc drive rather than database.
Sandeep Mewara 22-Apr-11 2:24am    
would be to store it on the disc drive rather than database
But we both know, customers can be rigid at times! ;)
You need to use a File Upload Control[^] (more details - MSDN link[^]).
You may also add a filter for file types[^].

Save the file on the disk, save the path in the database. And whenever you need to give a link to the path, retrieve the path from database and give a link to the client.

There are various examples on the web, you just need to search.

Hope this helps!
 
Share this answer
 
Comments
Monjurul Habib 22-Apr-11 2:54am    
nice links.my 5.
Ankur\m/ 22-Apr-11 3:17am    
Thanks!
For Upload

if (Fup1.FileName.Length > 0)
                {
                    a = Fup1.FileName.Split('.');
                    fileName = Convert.ToString(System.DateTime.Now.Ticks) + "." + a.GetValue(1).ToString();
                    FilePath = Server.MapPath(@"~\FolderToSave");
                    Fup1.SaveAs(FilePath + @"\" + fileName);

                    FullName = FilePath + @"\" + fileName;
                  
                    //Save filepath in your database;

                }


For showing PDF in your web page you can use iframe.

Hope this can help you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900