Reading a HTML resource file using asp .net - asp.net

I am trying to write a windows services that will generate email based on HTML templates. I want my HTML templates to be included in my project as resources. Do i have read these these template files as using filestreams or are there built in C# functions to read these files as resources.
Is there better way to use HTML files as templates for generating emails in asp .net
Thanks
SCS

You just need to create resource file (.resx), then fill it in key/value manner like key = "email_template", value = "your html template". And after you will have the class with the field called email_template, and it will provide you your html template without any additional coding.
UPD
O, also you could save your template like asp.net user control (*.ascx) and then render it to string with technique described in this article
The same variant possible in MVC world. It could be done this way

Related

How to see tags in a Powerpoint presentation

I am working for an office-add-in for PowerPoint. I need to assign some unique identifier to my files, so that files can be identified in any dot net application. I did similar work for Word using custom properties. But for PowerPoint there is no way to read/ write custom property using office.js.
The only way I found using tags:
https://learn.microsoft.com/en-us/office/dev/add-ins/powerpoint/tagging-presentations-slides-shapes
but when I add tags to the presentation, I am not able to see those tags in presentation directly, I am able to read/ write through code only. Also I am not getting a way to read these tags from dot net application.
Any help will be great.
I am storing my files to azure blob. And reading files in my dot net core application to identify whether it has been saved from an office-add in or not. I am using syncfusion library in dot net core application to work with files.
Try this:
Open a PPT file and add a few tags "wwwww", "yyyyy", "zzzzz".
Close and save the file.
Add ".zip" onto the end of the filename.
Use any unzipper program to unzip the file.
Search the folder of unzipped files for "wwwww", "yyyyy", "zzzzz".
This should tell you where/how tags are stored in the OOXML.
Your .NET app should be able to use the OOXML SDK to read the tags of a PPT file.
At present, Syncfusion Presentation library do not have support to read and edit the tags of PowerPoint elements. Please track the status of this feature from below link,
https://www.syncfusion.com/feedback/1800/create-and-edit-tags-for-powerpoint-elements
However, kindly try the below suggested workaround solutions to achieve your requirement,
Using Shape.Name property:
Add a shape with unique name while generating a document from Office-Addin. You can use Shape.Name property for this.
In .NET Core application, identify the corresponding shape by using Shape.ShapeName property of Syncfusion Presentation library and decide whether its generated by Office-Addin or not. You can refer below UG documentation for more details,
https://help.syncfusion.com/file-formats/presentation/working-with-shapes#specifying-shape-properties
Using custom meta-data on Presentation:
PowerPoint Javascript API documentation states that, when we apply the tags for Presentation object it’s maintained as a custom property of PowerPoint document.
Screenshot
If so, you can able to iterate the custom property of PowerPoint document using Presentation.CustomDocumentProperties API of Syncfusion Presentation library. You can refer below UG documentation for more details,
https://help.syncfusion.com/file-formats/presentation/working-with-powerpoint-presentation#adding-custom-document-properties
Note: This update is from Syncfusion team

asp.net mvc3 - external includes or sharing layouts across projects?

Ok, I'm still new to Asp.Net and MVC3. I'm becoming more familiar with things but still experimenting after finishing my first web application (a simple web form submission into a database). Now I am working on smaller projects such as converting some old ColdFusion web forms that submit e-mails. I've easily accomplished this in MVC3 but all of our web pages are in a separate content management system where our central HTML template is. I've already asked a question about this here and didn't get anywhere.
What we have is the majority of our web pages get exported from the CMS as straight HTML files, and only the ones that need database access or a programming language are exported as ColdFusion. It's very easy to "include" ColdFusion code to use inside of the template in our CMS. I would love to be able to use this HTML template in my mvc3 project but I've found no way to perform an "include" or link to an external file. I'm not sure how this would work anyway, so I settled on just copy/pasting the template to mvc3 and figuring out a way I can share this template (now a "layout") between all of the small projects I'll be working on. If the template changes I do not want to have to update every single little mvc3 web application. I learned about using "Areas" but it seems you can't just publish a single area to a folder on the web server, the whole project has to be deployed.
All I really need is a way for small mvc3 projects to use one template and these small mvc3 projects to be scattered all over our web server. Would this best be done in one large project that publishes to multiple different folders, or as many small projects that can share a common layout? Is either of these two possible?
After attempting and experimenting with all of this, I'm beginning to think MVC is not going to work with what I want. It seems better suited for intranet applications or entire web sites, not this little "here and there" applications like what I want. Should I learn Web Forms instead? I know I can "include" a aspx file inside our CMS much like I do with ColdFusion.
Do your templates have to be "exported" from the CMS? Or, can you have a template that "lives" on a static CMS URL? This is what we do for apps that need db access / can't be easily done within the CMS, but need to share the same look and feel.
What you can do is have your plain old HTML file live at a URL, for example, https://cms.domain.tld/templates/designxyz.html. That file will serve up a basic layout, except where your custom app content goes, you simply have the string "content goes here".
Then, from the MVC app, you can call this URL to get the HTML content as a string. Once you have the string, you can split it in 2 before and after the "content goes here" string. Then, in your layout.cshtml file, you can do something like this:
#{
const string contentPlaceholder = "content goes here";
var allHtml = GetHtmlTemplateFromLiveServer();
var index = allHtml.IndexOf(contentPlaceholder);
var topHtml = allHtml.Substring(0, index);
var botHtml = allHtml.Substring(index + contentPlaceHolder.Length);
}
#topHtml
#RenderBody()
#botHtml
If something like this works, you can then abstract all of this away into a HTML Helper, then reuse that helper in other projects (NuGet would be good for this).
_Layout.cshtml
#{
var options = new CmsTemplateRenderOptions
{
Url = "https://cms.domain.tld/templates/designxyz.html",
Cache = new TimeSpan(1, 0, 0);
};
}
#Html.RenderCmsTemplate(CmsTemplateRenderRegion.Top, options)
#RenderBody()
#Html.RenderCmsTemplate(CmsTemplateRenderRegion.Bottom, options)
Then, to update the layout for all of your apps, you would just publish changes to the https://cms.domain.tld/templates/designxyz.html URL.

Where should I store localized server-side files and how should I look them up when using ASP.Net?

I need to store some server-side files (email templates) in an ASP.NET application. The files will be localized. How should I store and look up these files, including a fall-back method similar to the resx approach?
Use a separate folder for each template, then create a file for each localization adding the culture code to its extension. So for the "welcome" email template, you will have something like this.
EmailTemplates\
EmailTemplates\Welcome\
EmailTemplates\Welcome\welcome.txt
EmailTemplates\Welcome\welcome.jp-JP.txt
EmailTemplates\Welcome\welcome.th-TH.txt
Use File.Exists(..) to check if the file exists and then fallback to the default English template.
You can get the current culture code by using the CultureInfo.CurrentCulture.Name property.
For more info on culture codes: http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentculture%28v=vs.71%29.aspx
I hope this puts you on the right track.

How can I create new PDF files based on a template where some text will be replaced?

I'm developing a CMS aplication in ASP .Net using WebForms and I'm looking for a way to create new PDF files based on a template.
This feature will be used to generate contracts where some placeholders will be replaced with the customer data.
What's the best approach to do that?
Edited: The templates will be static, the main content will never change from customer to customer, only some text in the beginning that will contain the placeholders to recive the customer data. The catch is that I must allow the owner of the application to upload new templates in PDF, with the predetermined placeholders in it to allow the replacement to occur.
I can think of two approaches depending on what type of template you are looking at:
1) Static Template - Say the template does not change with the data (Ex.some standard compliance form etc)
You can try something like iTextSharp, where you have your templates defined in your .net code, and you just "plug in" the relevant data and render the PDF via iTextSharp.
2) Dynamic Templates - Say your template isn't standard and is user customizable. In this case, I'd say go for HTML for designing and "print" the for to PDF. There are many components available.
You may also want to try out components like crystal reports.
I'd go with static HTML templates containing substitution tokens e.g. {FullName} which you can then replace with your data. Once you have created an HTML file like this, say in a StringBuilder, you can use PrinceXML or ABCPdf.net (www.websupergoo.com) to transform your HTML into a PDF.
I hope I am understaning this correctly but wouldn't using standard PDF Form Fields give you the functionality and features you require. Load the PDF template into Adobe Acrobat Full or Foxit Phantom and define standard PDF Form Fields on top of the PDF. Each field has a name, position, font etc.
Then just use a standard PDF library to fill in the PDF form fields and 'flatten' the form fields if that is required.
This solution allows the customer to design new PDF layouts and so long as they define form fields with names that match up then you will be able to drop in the replacement form with a simple file copy.
The iText or iTextSharp library should be able to do all of this quite easily. If not them there are many PDF libraries out there that can.

What is the best practice for using ASP.NET MVC to render lots of html or text files?

I have a lot of html pages, but I don't know how to display them through the asp.net mvc view.
I buid a view as my template and use asp.net mvc to insert html into the template and then render it.
But the question is that I must use FileStream to read the raw html-based files into memroy and then put it into view template, like ViewData["content"] = ???.
I just want to know if there are some other better ways to render static html files to the browser.
Did i describe the question clearly?
I guess you could do something like this:
using(var file = new StreamReader(htmlFileName))
{
return Content(file.ReadToEnd());
}
Note that the mime type automatically defaults to text/html, but you could optionally specify which mime type headers should be sent by supplying the type as an additional argument to the Content method.
I guess you also can point a iframe element from HTML to the target file url directly.
Alternatively you could write your own ActionResult that writes the contents of the file to Response.Output (could potentially avoid loading the entire file into memory at once albeit it might not be a big issue).

Resources