How to create HTML text from C# application? - c#

I have C# application that must store some information into MS SQL that
would be later sent to email with DB Mail.
Within C# application I have a class with several properties and I need to use it to generate email text. So what I would like is set up a template with placeholders for variables. I need to create text as HTML and plain text.
What tools, libraries would you
recommend for HTML?
Is String.Format() best alternative to
work with plain text?

I do this in other applications by having the e-mail body available somewhere (SharePoint list, data table) already in the right format, but with named placeholders, corresponding to the information you have in your application.
Then sending the e-mail means replacing the placeholder with the right information. StringBuilder.Replace works fine.

I would say the most important thing you need to decide is when to encode the text. If you are emailing text supplied byusers, you will want to HtmlEncode it before including it in an email. It's probably ok to store it "as recieved" in the data base as long as every consumer encodes it before using it. I typically do this in the data layer that "gets" data from the data base.

Related

How to create template and generate pdf using template and database data iText C#

I want to do below task using iText7.
create template using HTML or ..(some fields can be able to hide
according to user input)
Fill the template with the database data
generate accessible pdf
How can I do this?
As far as I understand, you want to have an HTML template where you will fill in data based on user input as well as data coming from your database. This is possible in iText in general, however you would need to do a lot of work, especially if you want to have a template for the PDFs that you are going to generate (as well as the template for the HTML form for capturing data).
It would be nice to have a tool where we design the HTML form and the form with which the output PDF is going to be generated interactively and maybe even using the same resources, sub-forms, sub-templates etc. Then the only thing the technical person would do is to bind the actual data to the form elements. The template will have the logic to show/hid elements or any other conditions that you might come up with. It would simplify the workflow a lot.
iText is working on a product called Dito which was announced in GIDS 2018 in Bangalore, India and a demo session was given. Dito is going to do exactly what you want and what I describe above. You can find the presentation here: http://www.developermarch.com/developersummit/downloadPDF/Dito.pdf
You can find also document workflow here: https://itextpdf.com/sites/default/files/attachments/LL_iText_Infographic_Flyer_A4-pdf.pdf

Email Parsing program

I am writing email parsing program. Basically, I am trying to retrieve the emails from exchange server and they have different formats. Mail body contains p and span tags, and when I open the message in Outlook, it is adding additional classes such as "msonormal" to the html elements. And when I copy and paste it in GMail composer it is just removing the classes but html tags are intact.
I am using HTML agility pack to parse the tags independent of class names. Emails are sent via different automated systems. So, I am not completely sure if the emails from the exchange server contains p and span tags or the outlook/gmail editors are adding those tags as well.
Can any one shed some light, do these mail editors just add the classes or any additional attributes or they completely change the layout such as showing divs as tables.
I'm sorry but if you are getting emails from different sources, chances are that they will all be formatted differently.
You're on the right track using html agility pack. I would suggest putting a break point in your code and getting the full html source of each and then parsing.
They are from different sources so you can conditionally parse based on sender or subject.
I've had to do this in the past, it was a pain, sorry there is no way to normalize all so they can be parsed in a standard way. The only way would be for you to enforce a standard on your senders, which I'm guessing would be almost impossible.

HTML Data Not Available On RDP/Terminal Services Clipboard

I'm parsing HTML data that is currently available on the clipboard (Clipboard.GetDataObject). However, I was surprised to find that when copying data from a webpage in an RDP session, the HTML format is not available and is instead replaced with "OEMText".
Can anyone discribe why this occurs or a way around it?
I think RDP just filters that out. It does pass RTF though, and some OLE formats.
However, "OEMText" is not a replacement, it's always available whenever plain text is present. You typically have Text, OEMText, and UnicodeText.

Mail merge or merge-like functionality from C#

I need to print a few thousand stickers with a few text fields (name, position, etc) as well as a barcode image.
Each staff member gets two unique stickers, and the sticker paper has 4 per sheet so that's 2 staff per sheet.
I already have all the code to generate the barcode as an Image, and the staff details are stored in a List of object.
If possible, I'd like to avoid using MSWord directly since my development environment is quite different from the target environment and I've had issues in the past from the disparity. (Win7-64, MSOffice2010 vs. WinXP-32, MSOffice2003).
What's the best way to accomplish this?
If I save the document as an XML format and replace the mail merge fields with unique tokens which I can replace with my actual values (and I can even replace the binary image data with base-64 encoded image bytes) then that works but it's clunky. For starters, I'd have to save the XML file and then somehow print it transparent to the user (don't want Word showing up). Also, the XML template is 1 page, but I might have several dozen to print. I can send each page to the printer individually but that's not exactly ideal.
Any other suggestions?
I would use DevXpress XtraReports as I have used it in the past in similar scenarios with great results. If you prefer other engines like Crystal or Telerik is the same, as easy as dragging some fields in the page details section and assign your object list as datasource. DevXpress has also a RichTextBox with builtin mailmerge feature. at last if you decide for word do not forget that you can automate and use it while keeping it invisible so users wont see it.

Parsing Data From a File on the server

I have an application on a server and I want it to send a file that can be parsed for the data I am looking for with as little human error as possible.
I am not sure what tags to attach to this it is being coded in C# though.
I was thinking an excel spreadsheet but it can be changed to easily from what I'm told.
What is a vaible way to recieve data to be parsed that can have any format?
Or
What is a way to enter data to get to the network without setting up a program?
Edit:
The server is on a diffrent network than the user wich they cannot directly access.
InfoPath is made for user form data like that.
Excel is another option, but you're right - its difficult to validate user input.
Google Spreadsheet's Forms feature is a nice alternative but getting the data from the spreadsheet afterward could be a pain.

Categories