Friday, August 31, 2007

How to create a site programmatically in WSS 3.0

As part of a project I am working on, I need to make a lot of sharepoint websites based off the same customized template. I'm obviously not going to sit there and click over and over, so here's how to do it in C#, I hosted this in an ASPX page and ran it on the server. SPSite newSite = new SPSite("http://server/siteurl"); SPWeb newWeb = newSite.OpenWeb(); newWeb.AllowUnsafeUpdates = true ; newWeb.Update(); SPWebCollection subsites = newWeb.Webs; SPWeb newSubWeb = subsites.Add("siteurl", "sitetitle", "sitedescription", 1033, "template.stp", true, false); remember to add a reference to 'Windows SharePoint Services' and add 'using' lines for: using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; The AllowUnsafeUpdates part of the code allows you to do your method in the GET section of the code, for example Page_Load, I believe you might not need this if you do your work in a postback, ie by adding a button to click. To create a custom template, I simply created a website, customized it, and went to Site Actions -> Site Settings then under look and feel clicked "Save site as template". When you fill out that page it is important to take note of the filename you give it! As this is used in the code above. I called mine BWJob, so my template was BWJob.stp. If you forget this name, you can find it in the Site Template gallery. If you want to use a default template, refer to Todd Baginski's blog, he has a list of what to write in the template section. This information is also available in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\XML\WEBTEMP.XML - it follows the strucutre of "Template Name#Configuration ID" so Team Site is "STS#0" instead of "template.stp". This method worked well for me.

Wednesday, August 29, 2007

Usability: Don't interrogate your users when asking them to register

I saw a really good example of how to do an online registration form properly today. I'm talking about the form you fill out to register for a website, usually for discussion forums.

You might know the ones, you go to a forum to realize you have to register just to view it, and then you are bombarded with questions, only a few of which are compulsory.

For example, you might get asked for a username, email address and password - these are compulsory, but at the same time, there is input field after input field asking you for all of your personal details, birthday, interests, do you have a website, whats your msn/aim/icq/skype/xfire/insertIMProgramhere - it's okay though, you don't have to put these in.

These types of sites annoy me, I, like most users, like things done quickly and pain free, it's annoying enough that you made me sign up to your website and then get a verification email from my inbox just to see if there is any active discussion, don't make things worse by making me look from text box to text box seeing if there is a * character next to it. I want to do the minimum amount of thinking, I'm not going to surrender my life story to you if I don't even know what the forums are like!

Sure, maybe later on, when I've decided to actively participate in your community, then I'll go to edit my profile and add in some details I'd like to share. But in the mean time, just show me what I need to do - make me think well maybe this isn't so much of a hassle after all, rather than dammit do I have to put all that in?

Here is the example of what I was talking about, well done

Tuesday, August 28, 2007

How to post HTML and other code on Blogger

On creating my last post, I encountered a problem - the code I put in the editor was dissapearing, or at least half of it was! I figured this was due to it being read as HTML code, and found from THIS blog post, that you need to use HTML entities instead of normal html tags. I didn't feel too much liek going through my document and changing every tag, so I went searching and found THIS, on the W3C site. You enter HTML code, it converts it to HTML entities ready for posting, easy!

Monday, August 27, 2007

An online solution for viewing DWF files, with capability to drag into Autocad

On the Autodesk Forums, I recently enquired about a way of replacing WHIP! for autocad, which allowed us to have an intranet with standard details for our cad users to open up, view, and if needed drag and drop into autocad.

When Autodesk discontinued WHIP! they replaced it with DWF Viewer, and more recently have released Autodesk Design Review.

After much playing around I developed the solution you see in the image (I've zoomed out on the drawing).

Our intranet had a javascript function for opening DWF's in a certain sized window, called dwfwin, I edited that to open an ASP.Net page with the address of the drawing in the querystring.

From then, I filled out the code for the Design Review embedded drawing, using the value passed in the querystring.

Here is the code I used:

<% Dim dwf
dwf = Request.QueryString("dwf")

Dim dwfxml

dwfxml = Split(dwf, "/")
Dim arraymax
arraymax = UBound(dwfxml)

dwfxml = Left(dwfxml(arraymax), Len(dwfxml(arraymax)) - 4)
dwfxml = "http://bwonline/dwf/xml/"& dwfxml & ".xml"
'response.write (dwfxml)

WIDTH="97%" HEIGHT="94%">

That worked fine for viewing drawings, though it was slower than our old WHIP! solution, due to the extra features it has, but it's not a big issue for us. Another problem was though, that it couldn't drag and drop the drawing into Autocad - which was the main point of the exercise. For this, we used I-Drop.

The idea behind I-Drop is that you make a picture of the drawing file, and that picture has an XML file behind it that tells the site where the .DWG file is that Autocad will import when that image is dragged and dropped. However I wasn't going to go through and make images of all our drawings, and we didn't need them wasting extra space so I came up with the idea of making the image a small 'D' (for drag/drop), and as you can see from the image above, that's what happened.

To do this, I needed to generate the XML file, as I wasn't going to go through and make them for each individual one, so I created some code to do it for me, using the System.XML Namespace. There is a certain layout you need to use for the I-Drop XML file, it needs to look like this:

<?xml version="1.0"?>
<package xmlns="x-schema:idrop-schema.xdr">
<proxy defaultsrc="d.jpg" />
<dataset defaultsrc="L:/acad/acad_str/drg-exs/1-9.dwg" />

The values that change are the d.jpg is the image used, and the .dwg file is the location of the drawing file. This was easy for me to generate automatically as the DWF's and DWG's are kept in the same folder on our network.

To generate this file, I added this code to the Page_Load sub of my aspx page.

'Construct xml file name from dwf input string
Dim dwf
dwf = Request.QueryString("dwf")
Dim dwfxml
Dim dwfdwg
dwfxml = Split(dwf, "/")
Dim arraymax
arraymax = UBound(dwfxml)

dwfxml = Left(dwfxml(arraymax), Len(dwfxml(arraymax)) - 4)

dwfxml = "D:\Inetpub\intranet\bwo2\dwf\xml\" & dwfxml & ".xml"
dwfdwg = Left(dwf, Len(dwf) - 1) & "g"

'check if it has already been written
If Not File.Exists(dwfxml) Then
'Write xml file

Dim xmlNewDocument As XmlDocument = New XmlDocument
Dim sb As StringBuilder = New StringBuilder



End If

Basically this works out what the name of the .xml file will be from the querystring inputted, in my case I made it the name of the .dwf file, but with the extension changed.

These XML files only need to be made once so I kept them all in the one spot, and made my code check if one was made, if not, it created it, so there would be a slightly longer load the first time - but then that would never happen again.

Then later on, in the body of my page just after the design review object I used:
<object name="idrop" classid="clsid:21E0CB95-1198-4945-A3D2-4BF804295F78" width="15" height="15">
<param name="background" value="background.jpg">
<param name="proxyrect" value="0,0, 15,15">
<param name="griprect" value="0, 0, 15, 15">
<param name="package" value="<% =dwfxml %>"/>
<param name="validate" value="1">
<embed width="15" height="15" background="background.jpg" proxyrect="0,0, 15,15"
griprect="0, 0, 15, 15" package="<% =dwfxml %>" validate="1" src="background.jpg" name="idrop">

With dwfxml variable being the generated name and location of the xml file.

A point to note is that IE7 has security on objects like these, where you will need to click once to turn on the object, and again to use it. But that's not much of a big deal.

So the user simply reviews the drawing, then when they wish to, they click and drag the D character into Autocad. All staff need the I-Drop plugin, and Design Review, so I have linked to those on the page if anything doesn't show up properly. Problem solved! All seems to work well!

Friday, August 24, 2007

Disabling Internet Explorers advanced security configuration

I came across this problem today, in server 2003 I couldn't click 'OK' on my own sharepoint page, I figured this was because of the enhanced security. To remove it, go to control panel, add remove programs, change to windows components, and 'Internet Explorer Enhanced security configuration' is a component, deselect it, and click next. It should disable it, then when you fire up internet explorer you should see:
Caution: Internet Explorer Enhanced Security Configuration is not enabled
Perfect! Problem solved, I can click OK now! My pages load faster as well.

Free OCR Program

I required an OCR scan on a peice of paper we had lost the electronic copy for today. Most OCR software is pretty expensive, and all have varying results. There didn't seem to be a windows open source solution on sourceforge so I had a look for freeware, expecting to get something with a 30 day trial that writes TRIAL TRIAL GIVE ME MONEY all over your document, however I was surpised to find Simple OCR, seems to be completely free. To scan my document, I used the scan to JPEG feature on our Canon 3170 photocopier, which splits each page up into a JPEG file and sends to my email, I saved these to a folder. I then opened Simple OCR, did a machine print read, added all of the JPEGS (hold down shift and add all of them), ok'ed the preview, then clicked convert to text, it did it's thing then split my screen into two and showed me everything it wasn't sure about - neat, makes up for it's downfalls by admitting them. I went through, much like Microsoft Word's spell check, and it highlights the original word in the image, and it's translation. A few errors, but it's better than typing out the whole thing - or paying lots of money! Then it was a matter of saving it as a word document, and fixing up the formatting.