MOSS : Running code when creating a site from a template? - c#

In MOSS 2007, is there a way I can insert a piece of code I wrote to run every time I create a site from a ready made template ??

You should do it with a feature, and give it a feature receiver that contains your code. Attach the feature to the site template. If you've made the template yourself, you can simply add it to its onet.xml. If it's a standard template, you can use feature stapling, which connects your new feature to an existing site template.
Note that in either case, your code will not run for sites that exist already, (unless you manually activate the feature there.)

Yes, you certainly can. I wrote a post on this a few months back. You have two options, either a feature with a feature activated handler, or using a ProvisionAssembly in your site defintions webtemp*.xml file. The latter is also how MOSS does the Publishing portal multi-site setup.
I wrote a short article on this a few months back:
http://furuknap.blogspot.com/2008/06/question-from-forum-post-at-httpwww.html
.b

Related

How to Apply Style Sheet to HTML Designer Only?

I am working on a Web application project and although I am an experienced Visual Studio developer almost all of that has been in WinForms, console apps, Services, etc. That is, I have very little experience with using VS to develop web pages (Web Forms, asp.net, etc.), however, I am learning how to apply my previous Web page knowledge to VS.
One thing that has been throwing me for a while is how to apply additional CSS files in development, that should not be used in production (because they are already there). Specifically, I am working on a set of pages (DNN module) that is being deployed into a larger website context.
This all works fine, except the VS Web Page Design Editor is nigh useless because it's WYSIWYG rendering is not even remotely close to what the page looks like on the site. I know why this is happening: the site (and DNN) have their own set of CSS files that are getting applied/added to the page.
I know that I could just add those same style sheets to my web page in development (using <link href=...> tags?), however, then the web page would be deployed referencing these CSS files twice (there's a bunch of them too).
So my question is, is there any easy solution to this? Is there some setting somewhere that I can just say "use these additional CSS files in development or in the Design Editor"? (I hHve tried to google this, etc. but I just find dozens/hundreds of articles about how to add or edit CSS in Visual Studio)
Unfortunately I think that may have mis-explained my need somewhat. The issue really is not a development vs production issues, but rather an IDE vs execution issue. When debugging the code or otherwise running it in development, it is still within the DNN test environment we have setup, so it does have the extra file even here.
This is really about the HTML designer, when i am using it it does not have these extra style sheets, so I cannot see what the work I am doing really looks like. Instead, i have to run it every time I want to see whether any change i make looks like it is supposed to. This gets extremely onerous, especially with how slow DNN is to compile and reload.
Hmm, do you have your web project setup to run on IIS instead of IIS Express?
Something I do is often just work in the project then Save and if needed build. Then browse to the Site on my machines IIS instance (right click file in solution explorer and select browse if using ASP.NET Web forms).
Once I have done that I can refresh my page. I also use #if Debug in my code to bypass user login and etc to make round tripping faster...

Get Html from Web page and create Setup project for Wpf Application (C#)

I'm trying to create a wpf application such as a movies library because i would like to manage and sort out my movies with a pretty interface.
I'd like to create a library with all my movies getting information from the web, but i don't know how very well.
I thought to get the information from a web site, for example imdb, but i don't know if it's legally to capture html from page to get the nested information.
It's my first desktop application and I would also like to know if it is necessary to create a database within the project and then create a setup project with specified script for deploy it.
Sorry for the confusion but i would like to know too much things :)
Thanks a lot in advance.
The legality of web scraping is a grey area. See my question, "Legality of Web Scraping vs Normal Use" and the corresponding answers for some insight.
Even if the legality is not a problem, web scraping is a flimsy approach because the webpage structure may change without notice, making your application suddenly useless until you update it to the new format. You are much better off using some sort of web API (if the site providing the information offers it).
Whether you need a database or not depends entirely on what your application will be doing and how you design it - it's not something any of us can tell you.
Same goes for the setup project - in fact I wouldn't worry about that until you actually have a working application. Take it step by step and keep the scope within control.
Yes I did not think about api.
It's a great idea, maybe use "themoviedb".
But if i create an application based on it, that has to show all the movies that you have stored on your hdd and get , for example, the posters, the description and the ranking, i have to create a database according to you?
Thanks a lot.

Content Editor for Client

I've created a website for a client of mine. It is coded in ASP.NET with C# and hosted on GoDaddy. She requires this website to updated daily by her. However, this client has very little knowledge of how to edit HTML or text within a site. I don't want to edit it every time she wants an update on the site.
What would be the best solution to my problem? I have looked up Content Management Systems, but I'm a little confused by what exactly it does in terms of coding and the management of the existing site. Does it require me to reformat the whole site to follow the CMS's 'templates'? Would it be better for me design my own back-end panel for her to edit the content (this would obviously take significant work)?
If you want to stick with a site you're developing from scratch, I'd use the HtmlEditor from the AjaxControlToolkit or a similar control, and store the html content in the database.
Then, when outputting the html from the database to the client pages, I'd make sure to use the Microsoft Anti-Cross Site Scripting Library to sanitize the html using the GetHtmlFragment() function (since this is tagged asp.net). It's not that much work, actually, if you design the database correctly, and if you've got the skills.
CMS systems are (trying not to oversimplify) entire web sites that are already built and allow people to edit the content using built-in content editing functionality. They range in functionality and extensibility from a "You get what you get and there's very little you can change" to "You can customize the heck out of it and buy or build your own modules to extend functionality." There are a lot of good ones out there, some free, and some expensive.

Fiddler/C#: search content of request/response for special phrases

this is my first visit to stackoverflow and right now I feel very comfortable with this site.
It already helped me to get the FiddlerCore embedded into MS Visual C# 2008 Express Edition.
Just needed to create a reference(Verweis) to the fiddlercore dll from Project Explorer(Projektmappenexplorer) in MS Visual C# EE. Hope this are the names for it in the english version. After this you can use Fiddler.FiddlerApplication stuff etc.
What is my task?
I want to create a small program which is able to use the FiddlerCore to check the bodies of requests/responds for special JavaScript Code.
This enables the developers to check wether their code is valid in another versions of there Browser (especially from IE 6.x to IE 8.x) or not. To be able to do so, I need to know:
How can I check the content of a requested or responded file for a String?
This must have something to do with the Text View Inspector (Fiddler), but I cannot find a possibility to access it with .net code or within Fiddler which would also help a lot already.
I should be able to finish the remaining stuff with some search by google or stackoverflow.
As this is my first time with .net languages this will be very interesting and demanding.
Take a look at this example. In the BeforeResponse callback a Fiddler.Session is passed as argument. This object has a method called GetResponseBodyAsString. As its name suggest you may try using it to get the response text. There's also a GetRequestBodyAsString method for the request.

can I execute an aspx file in a class library and get the result as a string?

I have an c# Class Library where I need some dynamic template based text.
Instead of inventing my own template parser I thought I could create an aspx file in my project that is executed at runtime and, instead of viewing the output in a browser, I want a StreamReader or string object that holds the result.
Is that possible? And if yes, how do I do this?
You're going to struggle more than is necessary with this approach. You'd need an ASP.NET host like IIS.
Personally, I'd recommend an existing template processor. I've heard (on a Hanselminutes or DotNetRocks podcast, I think) that you might even be able to host the T4 system in your application. I'll have a look and see if I've remembered that correctly.
Update
Here's a link on hosting T4 templating in your application.
ASP.Net is designed to be run in a web server engine - you would also have to deploy this to make it work.
Calling ASPX Pages from a Library would be possible (see Cassini WebServer) but I would recommend another tool:
http://www.codeproject.com/KB/cs/T4BasedCodeGenerator.aspx
We use it in our Project - slightly adapted for our needs

Categories

Resources