Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a web application, i have a file upload control,when file is selected then when user click on a button i am using ItextSharp to convert it page contend into string,this can be easily done in window form application using following code
C#
OpenFileDialog ofd = new OpenFileDialog();
           string filePath;
           //  string file;
           ofd.Filter = "PDF Files(*.pdf)|*.PDF|ALL Files(*.*)|*.*";
           if (ofd.ShowDialog() == DialogResult.OK)
           {

               filePath = ofd.FileName.ToString();
               PdfReader reader = new PdfReader(filePath);

how can i do same in web application?using FileUPLOAD CONTROL?PLZ
Posted
Comments
ZurdoDev 29-Dec-15 13:46pm    
Depends on the file upload control you use. But it should have an event like Upload_Complete() or something where you can get access to the file. Then your code will likely be the same.
Sajid227 29-Dec-15 14:16pm    
i am using Fileupload Control??any code help ?
ZurdoDev 29-Dec-15 14:28pm    
I won't write all of the code for you. See this for reference, https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload(v=vs.110).aspx#saving_uploaded_files

1 solution

The FileUpload Control does not pass you a file - it passes you a stream of bytes - so you need to look at your PdfReader Class constructor to see if there is an overload that takes a Stream, an array of bytes, or a string of data rather than a string path.
You can then convert the data appropriately and pass it to the constructor.

If the class only accepts a path to a file, then you will need to kludge round it and create a temporary file, write your data to do, open your PDF, process it, then close and delete the temporary file. Nasty, and prone to leaving large temporary documents "laying around" if anything goes wrong, so you'll want a mechanism for clearing those up as well...
 
Share this answer
 

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