Friday, 14 August 2009
Project: Custom Form (source code) for Netcommunity
Firstly, create a new web application in VS. Then delete 'default.aspx' and the accompanying code-behind file. Then, add 2 new Web User Controls to your project (read previous posts for an explanation of how to do that if you're not sure) - name them 'MyPartEditor' and 'MyPartDisplay' or similar.
Copy and paste the code from the text files into the relevant visual studio files. For example, 'editor-codebehind.txt' should be pasted into the code-behind of the 'MyPartEditor' control. I haven't included everything in the text files in terms of headers, so you'll have to add a reference to and include BBNCExtensions (see previous posts for an example). Use common sense and refer back to the previous posts if you get stuck - if you still can't do it, leave a comment.
One file - 'mailvars-codefile.txt' - needs to be placed somewhere special. Add a new item to your project, and select 'C# codefile'. Paste the contents of the text file into that. It's a standalone class declaration that both your editor part and display part can use to create instances of the 'mailvars' object, an object I've created to house certain properties such as the email address the form will use. Read through all the code and hopefully you'll understand how it all links together.
Once you're happy with how it works, you'll need to go through and change a couple of bits - for example, in the part of the display control that gets and sets a cookie, you'll need to change the name of the cookie to something a bit more meaningful. You'll also need to change the url that visitors are redirected to, as in the text files it points them to 'www.yoursite.org/netcommunity' etc.
Do all that, and you're ready to build and then deploy the project. Again, there are instructions for that in previous posts.
If anyone can be bothered to deploy this I'd love to hear about it.
Oh, and bear in mind that if you're running BBNC 5.1 you might have problems, as some of the calls reference parts of the API that weren't available in that version of Netcommunity. It's easy to get it to work with 5.1, though - find statements that look like this:
if (CurrentUser.IsInRole('Registered users')) {
And change them to this:
if (Netcommunity.CurrentUser.IsInRole('Registered users')) {
That should do the trick. (I think, the above is from memory, so if not let me know)
Oh, and the link. Download the source code here:
http://www.wii-uk.net/media/display-acsx.zip
Enjoy.
Thursday, 13 August 2009
Project: Custom Form for Netcommunity
- It checks to see if the user is logged in - if they are, it redirects them straight to the document (registered users will already have submitted their details once).
- If they aren't logged in, it checks for a cookie left behind when the form is submitted. If it finds a cookie, it redirects them to the document (as they must have filled in the form previously).
- If it can't find a cookie, it displays a form for them to fill in. Once they submit the form, a thank you message and a link to the relevant document is displayed.
The custom part uses querystring parameters to determine which document the user is trying to download. This means that instead of linking directly to documents on a page, like this:
www.mywebsite.com/netcommunity/Document.doc?id=560
We instead route the user to the URL of the page housing the custom part, with some parameters so the part knows where to direct the user:
www.mywebsite.com/netcommunity/Page.aspx?id=10&docid=1&doctitle=My%20Doc
This URL can be changed to point to whatever document is necessary - it extracts the document ID from the querystring (docid=1) and uses it to forward the user to that document once the form has been filled in / they have been identified. The 'doctitle=My Doc' parameter is purely for display - when the form comes up, it says 'Ah, you're trying to download My Doc - you need to fill in this form' (or words to that effect).
However, some content editors without much html experience might have trouble building a URL with parameters like this, so the next step is to create another custom part that will build the URL for them and include it on a page. Bonza.
Source code for the form and other stuff soon.