0

Is there a way to get the contents of files stored as binary in database? I want to get the content of pdf file to search in it.

For example search for particular word. I'm using ASP.NET MVC with EF6 and SQL Server.

This code for storing files in the database:

[HttpPost]
public ActionResult FileUpload(FileDetail Fd, HttpPostedFileBase files)
{
    String FileExt = Path.GetExtension(files.FileName).ToUpper();

    if (FileExt == ".PDF")
    {
        Stream str = files.InputStream;
        BinaryReader Br = new BinaryReader(str);
        Byte[] FileDet = Br.ReadBytes((Int32)str.Length);

        Fd.FileName = files.FileName;
        Fd.FileContent = FileDet;
        db.FileDetails.Add(Fd);
        db.SaveChanges();
        //other code
    }
    else
    {
        //other code
    }
}

Edit I will use iTextsharp thanks

shmookh
  • 49
  • 4
  • I've rolled back your edit as it **completely** changed the nature of the question. If you want to ask a different question, please *ask it as a new question*. The edit is not lost - the [text is here](https://stackoverflow.com/posts/49479836/revisions) - but I would suggest expanding on that question a little. You may also want to see https://stackoverflow.com/questions/2116440/extracting-text-from-pdfs-in-c-sharp or https://stackoverflow.com/questions/20523524/reading-text-from-pdf-in-net before asking that – Marc Gravell Mar 26 '18 at 08:58
  • I found answer to question likes my question here https://stackoverflow.com/questions/29127938/how-can-i-create-document-from-byte-in-itextsharp – shmookh Mar 26 '18 at 09:04
  • Marc Gravell, I'm sorry for that ,I tried to edit same question as you say not different question – shmookh Mar 26 '18 at 09:09

1 Answers1

3

you should just be able to load the relevant item from db.FileDetails to get a FileDetail instance, then read the .FileContent value - essentially the reverse of how you stored it.

If you mean that you are struggling to parse the text from the PDF - that's an entirely separate matter.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • @shmookh then I strongly suggest asking a question on how to extract text from a PDF, because your current question *really doesn't ask that* - if asks about EF, SQL Server, and ASP.NET MVC - all things that are completely unrelated to PDF contents – Marc Gravell Mar 26 '18 at 08:03