Tuesday, December 11, 2007
Tuesday, November 6, 2007
Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) 'inserts the ID of a match into the table. 'Use regex to find the id of the game. Dim MatchID As String = MatchURL.Text Dim r As Regex = New Regex("match", RegexOptions.None) Dim m As Match = r.Match(MatchID) Dim MatchLoc As Integer = m.Index Dim ScoreBegin = MatchID.IndexOf("/", MatchLoc) + 1 Dim ScoreEnd = MatchID.IndexOf(".", ScoreBegin) MatchID = MatchID.Substring(ScoreBegin, ScoreEnd - ScoreBegin) 'Inserting the CricketMatch key into PP_MiscValues table ' This gives the ID of the match for the score card to detect and use. If Not MatchID = "None" Then 'Submit it to SQL Database, your SQL implementation may/will differ. Dim _ibcon As SqlConnection = ibcon.ReturnConnection _ibcon.Open() Dim InfoBaseCommand As SqlCommand = New SqlCommand("Insert into PP_MiscValues (KeyName, KeyValue) Values _ ('CricketMatch', '" & MatchID & "');", _ibcon) Dim Result = InfoBaseCommand.ExecuteNonQuery _ibcon.Close() ' Confirm to the user that the matchID is entered Response.Write("Match with ID " & MatchID & " added, coverage has begun") Else Response.Write("No Match ID Found") End If End SubThat is submitted from a text box with a submit button, I also have a delete button which removes any entry from that table, thus ending coverage. From there, I created a web part, which looks in the database and checks for a CricketMatch record in the MiscValues table, if there isn't any, it simply says 'no games are currently being covered', if there is one, then it checks to see if there is already cached code for the match, if there is, it simply displays it. If not, it then screenscrapes the page, and stores it in cache, with an expiry of 1 minute. The code for this is:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) 'Check if a match is on, by checking for a MatchID in the database. Dim MatchID 'SQL Connection to check if there is a CricketMatch record in the database Dim _ibcon As SqlConnection = ibcon.ReturnConnection Try _ibcon.Open() Dim InfoBaseCommand As SqlCommand = New SqlCommand("Select KeyValue from PP_MiscValues where KeyName _ = 'CricketMatch';", _ibcon) Dim ResultReader As SqlDataReader = InfoBaseCommand.ExecuteReader While ResultReader.Read MatchID = ResultReader.Item("KeyValue") End While _ibcon.Close() Catch ex As Exception Response.Write(ex) End Try ' If there is a record in the database, check the cache. If Not MatchID Is Nothing Then 'Check if score is in cache If Cache("CricketScore") Is Nothing Then 'create web client instance for scraping Dim objWebClient As New WebClient() 'Scrape the page, getting the match ID from cache (idea is that you have another "admin" page to set this) 'Construct the URL of the desktop scorecard, using the MatchID Dim strURL = "http://content-aus.cricinfo.com/australia/engine/current/match/" & _ MatchID & ".html?template=desktop;view=main;wrappertype=frame" Dim aScrapedHTML() As Byte aScrapedHTML = objWebClient.DownloadData(strURL) 'Convert the Byte array into a String Dim objUTF8 As New UTF8Encoding() Dim strScrapedHTML As String strScrapedHTML = objUTF8.GetString(aScrapedHTML) 'Fix the bottom links on the desktop scorecard, they are relative, so they won't work anymore. strScrapedHTML = Replace(strScrapedHTML, " ' Remove the close window link strScrapedHTML = Replace(strScrapedHTML, " Close window", "") 'Replace the white text with black strScrapedHTML = Replace(strScrapedHTML, "", "") 'If it worked, insert into cache, with an expiry of one minute, so only 1 computer per minute scrapes the page. ' Could lower this to 30 seconds if you want scores quicker If Not strScrapedHTML Is Nothing Then Cache.Insert("CricketScore", strScrapedHTML, Nothing, DateTime.Now.AddMinutes(1), TimeSpan.Zero) End If ' Display cricket scores on page lblHTMLOutput.Text = strScrapedHTML Else ' If there was no value in cache, 'load the html from the cache & output it. lblHTMLOutput.Text = Cache("CricketScore") End If Else lblHTMLOutput.Text = "Currently no games are being played, this will be updated when one begins" End If End SubThat then nicely displays the scorecard once a match is entered, and then doesn't display it when it's removed. Of course, this will get properly stress tested come match day, but from my preliminary testing
Wednesday, October 31, 2007
Tuesday, October 9, 2007
Thursday, October 4, 2007
Firstly, aesthetically there are some menu changes, mainly in composing emails, Outlook is probably the worst example of the ribbon implementation in the whole of office, with it only partially implemented. It seemed somewhat unnecessary given that only email composition is affected by it, and that the cluttered menu of the main Outlook window remains (and some awful click counts when trying to access stuff like the manage forms menu - why isn't this in with the 'tools -> forms' menu?).
Then, despite kicking and screaming from anyone who sends HTML emails, they have changed the rendering of emails, from Internet Explorer to Word. It seemed somewhat silly given the release of Internet Explorer 7, but they've done it. It's added some cool Word-like features to editing of emails, and made copying and pasting from Word a breeze, but in the long run, you don't know what your emails are going to look like on the other users computer.
However this is not where I have had the most hassle, the company I work for recently purchased Office 2007 standard, seeing as we run an Windows SBS server, we already had Outlook 2003 licenses for all users, but seeing as we couldn't buy Office without Outlook we decided we might as well install it.
For a couple of years now, our company has been using Outlook 2003, with a Public Folder system for filing of all correspondence, despite Microsoft slowly prodding us towards Sharepoint, we can't see any reason too. As an engineering firm, all of our major documents and drawings are stored on a shared network drive, so they can be opened in Autocad. This works well for a company of around 60 employees. We just drag and drop our emails to the appropriate folder and thats that.
To simplify the filing process we have created a custom form, which has a field next to the subject field for our job number. This then sets the category of the email to be that job number, and carbon copies it to an account that will automatically file it. It's worked without glitch for a long time now. That is, until we installed Outlook 2007. It was claimed that even though there is a new way of doing form customization 'Form Regions', the old style will still work fine. It seemed to at first, emails still got filed correctly. However a number of problems started to occur.
Firstly, when trying to forward an email, that was received from someone externally (ie didn't use our custom form to create it), it causes the error "the messaging interface has returned an unknown error". We tried recreating the form from scratch, checking everything on the form, reinstalling Outlook etc - no luck.
Weirdly, on occasion it did magically work, but then it would stop again, and on any external email in the public folders it always did it.
Another major error, was that the custom form itself would randomly go really wide, or really small, and not scroll with text, see the pictures below for more details.
Not as annoying as really wide, as the text wraps so its just like a small window with wasted space.
Most annoying of all - form goes really wide, the project id field is off the screen and you have to tab across or use the new set of scrollbars to get to it. If you type text that goes of the screen, it doesn't wrap, and doesn't automatically scroll across, so you can't see what you are typing.
These are the two biggest problems, and most common ones, other ones include
- Automatic signature insertion does not work anymore
- On some users outlook, attachments just disappear, even though you can still select save all attachments to get them, they do not show up on the view message screen.
- Can't rename emails in your inbox anymore, previously we could rename the subject of a message that was in our inbox, this made for easier filing.
- For some reason there is a rule setup automatically that removes the category from all emails.. why? This makes it harder to see what project internal emails are related to.
- Outlook:\\ links in IE no longer work - why?
- Can't get rid of the bar telling you to enable instant search - we don't want to, Windows Desktop Search on XP slows down Autocad to a crawl!
- Opening shared calendars is dodgey at best, sometimes works, sometimes doesn't.
The rest of the Office 2007 suite is going brilliantly, just some caution should be had for any small business looking to use Outlook 2007. Until a solution to every one of the problems mentioned above is found, our company will be sticking with Outlook 2003, which really doesn't offer much less in terms of functionality.
Wednesday, September 19, 2007
Tuesday, September 18, 2007
The .adm file cpao12.adm is not in a valid format and must be replaced. Details: A string is expected at line 56.
The group policy templates for Office 2007 are a great help to system administrators, however upon installing them and setting the default template path for our workgroup – I received that error. (with the path to file before cpao12.adm)
A workaround courtesy of Felix on mcse.ms, edit cpao12.adm in notepad, and change every value of the following:
VALUEON NUMERIC 1
VALUEOFF NUMERIC 0
Do a replace all on that, and then while you are there, fix up outlk12.adm, changing:
VALUEON NUMERIC 1
VALUEOFF NUMERIC 0
VALUEON NUMERIC 1
VALUEOFF NUMERIC 0
There should be one instance of that (though there is a lot of outlook security keynames, so search for 'PromoteErrorsAsWarnings'.
Tuesday, September 4, 2007
I went through and spent alot of time considering each and every setting and selecting what I thought was best, then went to save my hard work and received this error:
I had no idea where this error came from, and a google search returned nothing.
So I experimented saving at regular intervals, and found that the error seems to be coming from the 'Office security settings' section, in the bottom box whenever I enabled 'Microsoft Office Excel - Application Add-ins warning options' it seems to crash. I just did not configure a setting from this and all seems to have gone well.
I'd say its a program bug, best to steer clear of that setting.
Monday, September 3, 2007
<object height="400" width="600"> <param name="movie" value="FlashFile.swf"> <embed src="FlashFile.swf" height="400" width="600"></embed> </object>
Friday, August 31, 2007
Wednesday, August 29, 2007
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 Babstats.com:
Tuesday, August 28, 2007
Monday, August 27, 2007
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).
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:
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.<% Dim dwf
dwf = Request.QueryString("dwf")
dwfxml = Split(dwf, "/")
arraymax = UBound(dwfxml)
dwfxml = Left(dwfxml(arraymax), Len(dwfxml(arraymax)) - 4)
dwfxml = "http://bwonline/dwf/xml/"& dwfxml & ".xml"
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:
<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
dwf = Request.QueryString("dwf")
dwfxml = Split(dwf, "/")
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
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">With dwfxml variable being the generated name and location of the xml file.
<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">
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
Caution: Internet Explorer Enhanced Security Configuration is not enabledPerfect! Problem solved, I can click OK now! My pages load faster as well.
Wednesday, July 25, 2007
This is something that I mentioned last blog, finally I've gotten around to posting it, on a side note, I'm also trying out the new 'blogging' feature in Word 2007, go to the office button, click new, and start a new blog post, it'll run through setting it up, and then away you go.. hopefully it works!
The scenario I had, was that we have a spreadsheet setup for collecting payments for the 'bar tab' we have for our social committee, who sell chocolates, chips, beer etc at a low cost. This is tallied up on a spreadsheet, and an email is sent around with amounts. I thought it would be good to have this data on each individual users intranet homepage. So I set about making a web part for it.
We didn't want to change the spreadsheet to an ASP form, as it was working fine as it is, and I didn't have the time to code one and teach the social committee treasurer how to use it. and I didn't have the time to code one and teach the social committee treasurer how to use it. So I thought, surely there is a way to extract the data out of an excel spreadsheet, and sure enough there is.
First off, I setup my cache as mentioned in my previous post 'using cache to determine a time for content reloading' so it only queries the excel spreadsheet once every 12 hours, so if the cache is still there, it doesn't get the new data, if not then it gets new data and adds something to cache. I decided that instead of having the data in cache, which could be deleted by IIS, and would require regular expressions to query properly, I would store it in a SQL table. So effectively I was synchronizing a couple of columns out of an excel spreadsheet with a SQL table.
I setup my SQL table, and then set about talking to the excel sheet. I stored it under the a folder on the server, and just gave the social committee people permissions to access and edit it – which probably isn't the most secure approach, but it was fine for what I am doing, and fairly idiot proof.
To talk to the table, you set up an 'OleDbConnection', I setup mine as follows:
Dim DBConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("~/SocCom/collection.xls") & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes""")
There I've got my data source as a mapped path to the xls file, and had its properties as an excel file. It connects using the Microsoft jet engine – similar to Access.
From then, I added a Try/Catch statement to catch errors which occur when someone is editing the file while it is trying to be accessed.
Dim SQLString As String = "SELECT [Name], [Balance] FROM [Collection Summary$] WHERE [Name] is not null and [Balance] is not null"
Dim DBCommand = New OleDbCommand(SQLString, DBConnection)
Dim DBReader As Data.IDataReader = DBCommand.ExecuteReader()
There I've opened the connection, and selected the columns with 'Name' and 'Balance' in the topmost cell – they need to be enclosed in square brackets. The From part of the SQL statement has [Collection Summary$] as that is the sheet name, the $ sign is required at the end (though my sheet name is only 'Collection Summary').
Also take note that I have added a where statement that does not show Null values of each column, this is important, as if you do not do this, then it will take more than 5 seconds to do the query, and will return a whole heap of null values, as it queries all the values in the spreadsheet, null cell or not.
That will return like a normal SQL query, you could bind it to a data grid, or whatever you like, in my case, I first deleted all the old values from my SQL table (I could have updated them – however employees leave and join, and spelling mistakes are corrected etc, so its better just to start a fresh each time) then did a 'While DBReader.Read' to loop through the values, writing them to variables, and inserting each to the database as it went.
At the end of that loop, I closed the DBReader, and DBConnection. Then added my catch statement:
Catch ex As System.Data.OleDb.OleDbException
Finally End Try
The exception was the System.Data.OleDB.OleDbException – which I tested was when the spreadsheet was already in use. As you can see I did nothing on the event of an error – as it doesn't matter if you can't read the data, I just didn't want the page to spit out an error – I wanted it to continue, which it does, and goes to the next line of code which is a call to my 'ReadFromDB()' sub procedure, which queries the database to get the data from the SQL table. So if there is an error, it goes to the ReadFromDB Sub, if not, it still goes there.
It then reads from that and prints my data. Done!
Edit: As a side note on my blogging with Word experiment, it worked great, however the formatted text I copied from Visual Studio 2005 added extra spaces, which is because it shows up as huge text in my editing menu, so each line break is size 72 or whatever it is. Other than that, worked brilliantly and was very easy.
Saturday, July 7, 2007
ASP.Net: Using cache to determine a time for content reloading (rather than reading data from cache)