How to access files within the wwwroot folder of a different project? - c#

I have 2 projects that are needing to talk to one another. The first is a ASP.NET MVC project, that when in production, has a feature where the user can edit an html template that is stored in the wwwroot folder of the project.
The second project is a C# console app that grabs some user data from a database, and then uses that data to email surveys to users. The html template from the first project is needing to be grabbed by this console app so that it can be used in sending out these emails. I was hoping to use HtmlAgilityPack to grab the html email template from the first project when it is live, something along the lines of this:
var web = new HtmlWeb();
var document = web.Load("www.sitename.com/EmailTemplate");
string text = document.ParsedText;
But I'm open to other ideas that might work in this case. More or less I think I just need to figure out how to access static html files from within the wwwroot folder from a browser path, if that's possible. Oh and these two projects are going to be running on different servers, so local paths won't work. Thank you!

In large part thanks to ADyson's comments, the course of action that makes most sense in this situation is to create a small API within the MVC app, that fetches the html file, and the console app will call this API to retrieve the needed html.

I had a similar problem, and I did it by adding ~/ in the beginning of my static file addresses in my _Layout.cshtml.
My template files and photos were no longer loaded in the project but the layout was loaded. This way the files were also loaded

Related

WKWebView - Xamarin code to extract, store and display web page along the resources (img, font, js, css etc.) for offline viewing

Is there any library in Xamarin which would store the pages that we browse in WKWebView?
Have to store the resources of the pages (CSS, fonts, js etc.) for offline viewing. The complexity is maintaining the folder structure and manage the resource Urls within the CSS and JS files. Any idea how the resources can be stored and loaded?
There are resources on how to save a html page and load the html in WKWebView.
Please note that this question is not about that. It is more about storing and managing the resources of the visited pages for offline viewing.
I don't think you're going to get your answer with a mobile only approach. It's not impossible to create one but I don't believe anything exists that will do what you want, happy to be proven wrong. I think you need to think outside the square a bit.
I can't give you the entire set of code because I don't own it (my company does) but I managed to take a website completely offline (with limitations of course) by using multiple resources to achieve the desired outcome.
I used a piece of software called Cyotek WebCopy in an Azure VM to scrape all of the website down to a folder. That folder was then zipped up and uploaded to Azure Blob Storage so it could be accessed from anywhere. The Xamarin app would then access the storage container, retrieve all of the blobs and then when a user clicks on a specific blob, it unzips down to the device and then opens up in a web view for the user to browse.
All of this was achieved using a web service and PowerShell scripts on the VM side and then of course your standard Xamarin based application for viewing.
Like I said, there are limitations to this but barring external links and database calls (like a submission page), it will work for you. It has worked for us.
It may sound like a lot of work but all in all, the VM side took me about 2 days and the Xamarin concept about 5 so all in all, not long to stand something up that is able to be built upon. I hope that helps.

I can't render pictures in an HTML generated PDF

I got an issu with the plugin IronPDF. I'm trying to render HTML and CSS display to a PDF files, it work in our web application, but now I'm trying to do the same stuff with a windows service. I tried to use Bootstrap locally to get CSS, that didn't work so I used CDN link and it worked. But now, I would like to use pictures, so I pasted a folder in the root of the project with pictures in it, I think it's an application root problem (Ibelieved that the application root was the root of the project, but it seems to be wrong)
I would like to have something like this:
https://prnt.sc/gvzvpg
but instead, I have something like that :
http://prntscr.com/gvzw1r
thanks for attention
I used before ItexSharp for generating PDF files with c#. For images, the path must be relative path. try it

Render html files from ASP.NET Razor cshtml files

I have a web app built with ASP.NET 4.6.1 and uses the Razor view engine. Is it possible to execute a command that will render all my template files (.cshtml files) to static HTML?
I need static HTML files for certain steps in my build process and I can't think of how to render all my view files into html.
I was thinking of something like what you are talking about, but my idea was a way to generate JS files (for building PhoneGap apps, for instance). The project was on BitBucket. The controller/view can generate the JS files necessary for executing the app, which was done by going to a URL to render the content, which you can view in the demo app. Any controller in the app marked with a special attribute gets rendered out to a target folder.
I was hoping to invest more into it but didn't get too far. However this was pretty easy to setup so I hope it can give you a starting point. At worse, you can create a process that spawns a browser to target this URL... At best, there is probably a better way to internalize the components to run "out of band."
Not sure if exist a easy solution for that. But if you really need it through the build process I suggest to create a consoleApp and call it from the build.For the console you can use the RazorEngine it compile/parse the razor for you.

Display local html page inside WebView

I have an html file (which consists of both text and images) in my Documents library (it need not exactly be over there, what I mean to emphasize is - it's not in the internet and not included within the app package since it's dynamic content and created after the app has been deployed).
I want to display the contents of this page within a WebView. How would I go about doing that ?
You can (and should) copy your HTML Files to the LocalState Directory of your App which sits here: C:\Users\YourUSerName\AppData\Local\Packages\YourApp\LocalState.
You then can Access this with: ms-appdata:///local/
Very Basic example:
string url = "ms-appdata:///local/myWebpage.html";
webView.Navigate(new Uri(url));
You can find a lot of Information and samples in this sample download: https://code.msdn.microsoft.com/windowsapps/XAML-WebView-control-sample-58ad63f7

Creating the XML file on the Another Website

I am working on a Web Site, which have 2 domain one for end users(www.test.com) and for Admin Panel(www.admin.test.com), I am creating the Site map from my Admin section(www.admin.test.com), Now I want when I will create(save) the Site map then My XML file will generate on the Root of the main website(www.test.com).
Can any one suggest me how I am achieve this, I am newbie in asp.net.
If you think both of the domains will be in same physical server, then you can just add path to your physical folder in the test.com site and create xml using it.
If you think that will not be the case, you can simply create a web service on front end that will take care of it.
In most of the cases, first cases is true and you can easily generate xml in www.test.com folder without any problems.
Thanks
Prashant

Categories