Blazor pdf File Read/View from SQL Server - c#

I am currently building an application using Blazor with a SQl database. The application allows for a user to upload pdf files to the server.
I've been searching for a simple and efficient way to read/view the pdf files from the SQL server but can not seem to find anything relevant.
I would prefer not to use JavaScript like in : https://www.pdftron.com/blog/webviewer/add-webviewer-to-blazor/
Anyone got a solution to this? Any help or tips would be greatly appreciated.

You could get the pdf as a byte array and render that in iframe.
Here is a similar question
just the source of data is different. If you store the data as a BLOB in the SQL server you should able to grab the data and convert it to base64.

Related

Upload files to solr in C#

I am trying to make an application in Windows Form Application in C#. In my project I have added solr. I will upload files (json, xml, csv, txt, or database) and I will do the searching. I can do the filtering or searching by using solr in C#. However, the problem is I can't submit or upload the files to the system. For instance, I want to upload a database to the system. I have already done the query part so that I will do the filtering and searching. But as I said I can't do the file upload part.
I am doing my interface in C# so that I will not use the solr interface. Thats why, I need to submit/upload choosen file when button pressed.
Is there any way to do that?
Do you have any suggestion for me?
why don't you try uploading file to server & instead of saving file to the database!
while uploading a file, convert it into zip & then save it to the server folder, & save path of the file in the table.

C# create pdf documents with no need of High permissions on the server

I have a C# proyect where I need to create a pdf document. I did it using the iTextSharp dll but when I ran it on the server it didn't work. It seems that the dll needs higher permissions than the one I have on my shared server.
Is there any other free way to do this? I'm trying to create the pdf from a grid I have, I don't care how I create the document (from html, code behind, etc) as long as it works.
does anybody know how to do this?
regards!
iTextSharp is just an assembly the contains an API for generating PDF's. It does not require any more privileges than your ASP.NET application.
Are you by chance trying to write the PDF to disk? Your ASP.NET process may not have write access to the location you are writing to.
I would suggest a better way is to output the PDF directly to the Response stream, assuming you are returning the PDF to the web user.

MS Access, SQL Server image field

I have spent nearly 2 days in trying to figure this out. We have an Access Project (adp) from Year 2000 that stores images to SQL Server 2008. I have tried connecting directly to SQL Server and to open TIFF files but it didn't work. Also tried to copy/paste the image field content into a file, renaming as TIFF and trying to open it but it didn't work as well. The problem with the content in the image field is that it is not of the right size. It is only 15-20KB but the files at that point should be around 3MB. It works fine if I retrieve the same data back in to the ACCESS project application.
I have tried TiffLib.net and few other things.
So, has anyone got any idea on how to migrate those image fields into SQL?
Thanks
Well the Image data type stores a binary version of your image.
Now the conversion process is explain in the below links.
You'll need to use a library to convert a byte array into image object.
http://www.akadia.com/services/dotnet_load_blob.html
http://www.dreamincode.net/forums/topic/103960-save-and-retrieve-images-with-sql-server/
Hopefully this helps.

Save a binary file in SQL Server as BLOB and text (or get the text from Full-Text index)

Currently we are saving files (PDF, DOC) into the database as BLOB fields. I would like to be able to retrieve the raw text of the file to be able to manipulate it for hit-highlighting and other functions.
Does anyone know of a simple way to either parse out the files and save the raw text on save, either via SQL or .net code. I have found that Adobe has a filtdump utility that will convert the PDF to text. Filtdump seems to be a command line tool, and i don't see a way to use a file stream. And what would the extractor be for Office documents and other file types?
-or-
Is there a way to pull out the raw text from the SQL Full text index, without using 3rd party filters?
Note i am trying to build a .net & MSSql solution without having to use a third party tool such as Lucene
If it isn't absolutely necessary to stream directly from SQL Server into your app, the hard part is parsing the PDF or DOC file formats.
The iTextSharp library will give you access to the innards of a PDF file:
http://itextsharp.sourceforge.net/
Here's a commercial product that claims to parse Word docs:
Aspose.Words
Edited to add:
I think you're also asking if there are ways to make SQL Server Full-text Indexing do the work for you by adding IFilters. This sounds like a good idea. I haven't done this myself, but MS has apparently supported a Word filter for a long time, and now Adobe has released a (free) PDF filter. There's a lot of information here:
Filter Central
10 Ways to Optimize SQL Server Full-text Indexing
SQL Server Full Text Search: Language Features - a little out of date but easy to understand.
SQL Server Full-Text Search feature uses IFilters for extracting plain text from PDF or Office file formats. You can install IFilters on your server or if your code is running on the same machine as SQL Server you're already have it.
Here is an article which shows how to use IFilters from .NET: http://www.codeproject.com/KB/cs/IFilter.aspx
You could from your C# application open the .doc file and save it as text and put both the text and .doc document into the database.
If you are using SQL 2008, then you could consider using the new FILESTREAM feature.
Your data is stored in a varbinary(max) column, but you can also access the raw data via a regular Win32 handle.
Here's some sample code showing how to get the handle.
I had this same issue... I solved it by adding the following to my application:
EPocalipse.IFilter.dll (for everything -but- Office 2007
documents, due to 64x Windows issues)
OpenXML SDK 2.0 (for Office 2007 Documents)
I use these to grab the plain text and then store it in the database alongside the binary data. Keep in mind that I am certainly not an expert, so there may be a better way to do this, but this works for everything but "Quick Save" pre-2007 Word Documents, which apparently aren't read by iFilters. I just have my users resave the document if that error occurs, and everything works fine.
Let me know if you'd like some sample code... I would post it right now, but it's a bit long.

How do CMS upload images?

I am just playing around and trying to make a very simple CMS. Right now I what I do right now is I use "FtpWebRequest" to get the file that they want to change around and stick it into a jquery plugin call html area(rich html editor).
Now I am wondering how could I allow them to add images that are not already hosted? Ie not on imageshack or something.
I am guessing I need to somehow upload the file and then store it somewhere but not sure how to do all that.
Thanks
A common approach for CMS systems that need to work in low-trust environments (like shared hosting) is to use the FileUpload control, and save the uploaded file as a binary (BLOB) in a database. This avoids dealing with the headache of disk access rights on the web server.
If you're using SQL Server, here's a great article on the database side of things (storing images as BLOBs).
The .NET side of things is pretty straightforward. The FileUpload.PostedFile property has all the information about the uploaded file, including a byte stream of its data.

Categories