Creating prepopulated aspx files with c# - c#

My objective is to write a program that can create folders and within those folders create Default.aspx pages. The Default.aspx pages must read information from the database to populate the page using their containing folder name as a parameter to call the database.
Create the folders is the easy part, but I'm not sure how to go about writing information to .aspx files.
The goal of this project is so a real estate company can create pages for featured properties (through a cms), each featured property getting it's own folder/page.
Any feedback would be great.
-Aaron

Rather than physically creating the .aspx files, I think it makes more sense to have 1 .aspx file, which is passed querystring values to return different content from the CMS, depending on its value.
Furthermore, you could use URL Rewriting to make the file appear as if its in a physical location, within a folder.
For example:
/Property.aspx?agent=EstateAgent1&name=Property1
Can be rewritten to:
/EstateAgent/Property1.aspx
If you have to generate folders and files, I'd recommend simply generating HTML files, as theres no need for the file to be dynamic, or ran at the server

I would create a template ASPX page, and copy that template into the new folders. Within the template, define the layout and add all of the necessary controls for displaying the data. Doing it this way, you can change your template as needed for changes, and after the template is copied to the folder you can customize it as needed.
I would be remiss not to warn you that this approach will be very difficult to maintain though. Unless there is some requirement I'm unaware of, I don't know why this approach would be favorable.
Hope this helps.

Related

Cannot access to physical HTML file

I'm migrate my old fashion asp.net MVC application to an angular application.
I've created a subset of .html files that contains templates that will provide the HTML code to build my angular components.
Problem
I want to put this html files inside the folder "Views" that already exists on my application. But when I try to access to .html files I receive the following message:
But if I put the .html files outside this folder I can access directly to them:
Questions
Can you tell me why this is happening?
There is anyway that I can access to html files inside the folder "Views"?
To make a long story short, the Views folder is a special folder that holds templates used by actions that are routed by ASP.NET MVC. Because of this, you cannot use it to hold files that are meant to be used directly.
I would suggest ditching the .NET Framework all together since you are going Angular.
If that is not an option or you would like to retain ASP.NET MVC functionality, then simply use another folder (like you have already done by moving the Templates folder to the root).
Try adding an explicit ignore in your RouteConfig
routes.IgnoreRoute("{file}.html");
That should prevent the default routing from taking effect
To make this work, I suggest you take the html markup in your html file and put it on a .cshtml view, that you will render using a GET action in the home controller for instance (as you would normaly do in the MVC pattern).
The other way to achieve this (which I don't recommend), is to add your html file to a deployable folder (like the js folder for javascript files), and than you can call your file using a direct link, however you will lose any capabilities of the MVC pattern this way.
Hope this helps.
As html files are working in views folder, Can you check the path i.e 'Editor/V2/Templates' after 'Views' folder whether it is correct?

Create Print Template

I have a web services application where I would like the users to be able to define print page templates with database field placeholder in my project.for this reason I
have to provide environment for design template for my users.this templates must save in database,
then for print I get data from database and put it in placeholders.I found that "XSLT" can be usefully for this issue, but a big problem is Html result for XSLT.If There is any solution please let me know.
thanks in advance
what you can do is: create a html file template, create field placeholder in it. When you need to print it, load data from database, replace the placeholder, create the html file, load it into webbrowser class (it does not have to have an UI). then print from there.
since it is html file, you can save it to database too.
it works great in one of our project which has the same requirement.

URL Rewriting from Winforms or console application

I'm importing classic ASP pages into a new Sitefinity installation. Unfortunately, the existing site makes extensive use of URL rewriting via Helicon ISAPI Rewrite 3.
I'm generating the list of pages that need to be imported by crawling the navigation menus in the old site. These are, unfortunately, not dynamically generated from any sort of central repository, so the best way I've found to build the site hierarchy is to crawl the site.
When creating page nodes in the Sitefinity nav hierarchy to hold the content from the old pages, I need to be able to create the new pages at a location roughly equivelant to their location in the file system in the old site. However, the rewrite rules make this difficult to determine. For instance, I may get a link form parsing the old HTML like:
http://www.mysite.com/product_name
which is rewritten (not redirected) to
http://www.mysite.com/products/product_name/product_root.asp
I need a way to get the second url from the first. The first thing that comes to mind is to somehow use the .htaccess file to parse the URLs, get the result and use that for the rest of the import process.
Is there a way to do this from a Winforms app without having to involve a web server? I realize that I could modify one of the ASP includes, such as the page footer, to emit a comment containing the rewritten URL of each page, but I'd rather not make unnecessary changes to the existing code if it can be avoided.
Update
For example,
http://www.keil.com/arm/
rewrites to
http://www.keil.com/products/arm/mdk.asp

Is it possible to do this in a C# ASP.NET Web Application?

I would like to write a Web Application that would have two buttons and directly from the browser would allow me to open two simple text files (using a File Open dialog box or something similar) and would then proceed to read in contents of those files and store them inside of a two strings. The key point here is that the exact files used to read from I don't known at runtime so it would be up to the user to select the files.
The goal is to be able to later compare those two strings but that part I already know how to do. My questions is this - is it even possible to do this inside of a Web Application (i.e. to call a File Open dialog box to allow the user to select files to read from) or would security limitations or some other Web Application related constraints prevent it from being done?
If it is possible, I would appreciate some sample code describing how to open files and how to read in contents of the selected files into strings. Othwerwise, I would like to know if it's not possible and I should consider doing a desktop application or try an entirely different way.
Thank you!
It is possible, but you would wind up having to upload both of the text files to the server and read the files into strings server-side.
All you would need to do is add two separate FileUpload controls to the page along with a button to post the files to the server.
If you don't want the page to refresh, you could always do the comparison via AJAX using the AsyncFileUpload control from the ASP.NET AJAX Toolkit.
Update
Reading the contents of the file should be relatively easy (as long as they are plain text):
var reader = new StreamReader(fileUploadControl.PostedFile.InputStream);
var contents = reader.ReadToEnd();
One way is to use the ASP.NET AJAX AsyncFileUpload control.
http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
In order to access the files from the server-side code (C# code) you'll need the user to upload them. The standard way to do this (and, for security reasons, the only way upon which you should rely) is with a file input element. In ASP.NET, you can use the FileUpload control.
You would essentially give the user two of these controls with which they can upload the two files. Then you'd read their contents on the server, save them however you wish (as files, to a database, just in Session for temporary use, etc.) and perform your logic on that data. Then build your output (the comparison part, which you said you have already) to display on the page refresh.
Be mindful of concerns such as what to do if the user tries to upload non-text files, very large files, etc.
That is not possible alone with JS. You would have to build a file upload (and store session information) or use Silverlight and a Javascript-Bridge to your Web-Application.
Here's an example for a FileOpenDialog in Silverlight: http://www.silverlightexamples.net/post/Open-File-Dialog-in-Silverlight.aspx
Here's an exmaple for a file upload via C#/Webforms http://support.microsoft.com/kb/323246

Home/Landing screen design for a website in asp.net

I have an web based application. The content for the Home page has been currently mentioned in the HTML code for the Home page using , and tags. To change the content anytime in future, it needs to be changed in the HTML code. :(
Is there a way that we can pick up the content from some external place and get it reflected through the website. This ways, any change if required can be made at the external location without referring to the application's code.
Please advise if there is any solution for it.
Thanks.
You can
Use a database
Include external files using Server Side Includes
Read external files and write their contents and an alternative method
Sounds like you're looking for a Content Management System (CMS), which will allow your content editors access to modify only specific blocks of a page that you specify.
There are a ton out there to do what you want, so you don't have to start from scratch. Just Google 'CMS'.
Although I haven't used it myself, DotNetNuke is a popular one these days and has a free version.

Categories

Resources