Resource files for Classic ASP

I was looking to localize a classic ASP website, and was considering upgrading it to ASP.NET, but it seemed way too much work, so I decided to look to see if it was possible to create a localization framework for classic ASP. using the same type of resx files that are used for asp.net
 
So, given a simple piece of xml in semi-typical resx format:
 
<root>
 <data name="Hello!">
  Ciao!
 </data>
</root>
 
I then wrote an include file in classic asp, to handle translations in the form
 
<%=Translate("Hello!")%>
 
(Precursed by a initResources("strings-it.xml"))
 
 
 Dim xmlResx
 Function initResources(ResourceFile)
  Set xmlResx=Server.CreateObject("Microsoft.XMLDOM")
  xmlResx.async=false
  xmlResx.load(Server.MapPath(ResourceFile))
 End Function
 
 Function Translate(english)
  Set objLst = xmlResx.getElementsByTagName("data")
  For i = 0 to (objLst.length -1)
    EnglishText = objLst.item(i).attributes.getNamedItem("name").text
 If english=EnglishText Then
  Translate= objLst.item(i).text
  Exit For
 End If
  Next
 End Function
 
20 Lines of code, prevented an overhaul of my application to .NET.
 
Ultimately, I plan this to be used for a spanish version of www.openmerchantaccount.com
 
 
 
 
Categories: Uncategorized

ASP.NET Crash on “OnBubbleEvent”

When debugging an ASP.NET application, I suddenly got an "Object Not Set to a reference of an object" error on OnBubbleEvent, which leads into unmanaged code in the .NET framework.
 
Simple solution, CTRL-ALT-DELETE, hit asp_wp.exe, and kill the process.
 
It works fine afterwards.
 
Categories: Uncategorized

Capturing a webcam to an AVI file

I previously wrote an application which captures a webcam in VB.NET (http://www.webtropy.com/articles/art7.asp) However, this only shows a webcam, and has no facilities to record. Therefore, I added a new function to save bitmaps
 

Public Sub SaveBitmap(ByVal filename As String)

SendMessage(lwndC, WM_CAP_FILE_SAVEDIB, 0&, filename)

End Sub

 

Where WM_CAP_FILE_SAVEDIB is defined as WM_USER+25

– It also requires an overloaded SendMessage declaration, which accepts a string as it’s final parameter.

 

I then found some CS code which converts BMP files to AVI (http://midget3d.com/gabe/AviLib.zip)

 

then used this to write bitmaps to disk, and build them into an AVI

 

saveFileDialog.Filter="*.avi|*.avi";

saveFileDialog.ShowDialog();

string strAVI = saveFileDialog.FileName;

string strBMP = saveFileDialog.FileName.Replace(".avi",".bmp");

AviWriter aviWriter =

new AviWriter(strAVI, AviCompression.None, 24, 320, 240);

isRecording =

true;

while(isRecording)

{

webcamControl1.SaveBitmap(strBMP);

aviWriter.WriteFrame(

new Bitmap(strBMP));

Application.DoEvents();

}

aviWriter.Close();

 
 
 
Categories: Uncategorized

Compress an AVI movie using C#

I was looking for a way to compress an AVI file down without loosing quality, and to do so programatically, in C#. All I found on the web, were commercial components. However, I just found out you can use QuickTime in C#, to compress the files down in size.
 

private bool ConvertToQuickTime(AxQTOControlLib.AxQTControl Control,string fromFileName,string toFileName)

{

this.axQTControl1.URL = fromFileName;

if (!axQTControl1.Movie.CanExport) return false;

QTOLibrary.QTQuickTime qt;

qt = axQTControl1.QuickTime;

if (qt.Exporters.Count == 0) qt.Exporters.Add();

QTOLibrary.QTExporter exp;

exp = qt.Exporters[1];

// Set exporter type: AVI, 3G, MPEG-4, PNG, etc.

exp.TypeName = "QuickTime Movie";

exp.SetDataSource(axQTControl1.Movie);

exp.DestinationFileName = toFileName;

exp.ShowProgressDialog =

true;

exp.BeginExport();

return true;

}

Categories: Uncategorized

Converting HHC files to HTML files

Categories: Uncategorized

Converting a DataTable to a Hashtable

Categories: Uncategorized

Parsing WindJet routes

Probobly a particularly niche field, but I just developed some code to parse airline routes from the website VolaWindJet.
 

private string GetWindJetRoutes(string HTML)

{

string outRoutes = "";

// Step 1. Delete between FL_Departure> and /SELECT

string strOutboundRoutes = DeleteBetween(HTML,"FL_Departure>","/SELECT");

MatchCollection mcDepIata = Regex.Matches(strOutboundRoutes,"value=(?<FromIata>[A-Z]{3})");

// Step 2. extract ToIata Array

string strRegex = @"arrayVoli[(?<IDFrom>d+)][(?<IDTo>d+)]=new.Option(‘w.*'(?<ToIata>w{3})";

MatchCollection mcDestIata = Regex.Matches(HTML,strRegex);

for(int iMatch=0;iMatch<mcDestIata.Count;iMatch++)

{

int intIDFrom = Convert.ToInt32(mcDestIata[iMatch].Groups["IDFrom"].Value);

string strFromIata = mcDepIata[intIDFrom-1].Groups["FromIata"].Value;

string strToIata = mcDestIata[iMatch].Groups["ToIata"].Value;

outRoutes += "’" + strFromIata + "’,’" + strToIata + "’rn";

}

return outRoutes;

}

 

Might be of interest to someone out there…. (or if not, my own personal reference)

Categories: Uncategorized

Sage Data Objects for .NET

I’m working on a .NET wrapper for Sage Data Object (SDO).  This is my first (working) attempt at using the Sage code in .NET (C#) to import products.
 

Interop.SageDataObject111.SageDataObjects sdo = new Interop.SageDataObject111.SageDataObjects();

Interop.SageDataObject111.WorkSpace wsStock;

Interop.SageDataObject111.StockRecord srStock;

wsStock = sdo.GetWorkSpace();

string strACCData = @"C:Program FilesSageAccountsACCDATA";

wsStock.Connect(strACCData, "MANAGER", "", "ThisIsUnique");

srStock = (StockRecord)wsStock.CreateObject("StockRecord");

srStock.MoveFirst();

object objDescription = (object)"DESCRIPTION";

string strDescription = srStock.Fields.Item(ref objDescription).Value.ToString();

MessageBox.Show(strDescription);

wsStock.Disconnect();

 

Object model is still quite messy. Going to try to clean that up, and put some decent help files together.

Categories: Uncategorized

Making a server-side click work when Javascript is disabled

A client’s accessibility guidelines stipulated that a particular asp.net website was supposed to work, even when javascript was disabled. ASP.NET relies heavily on __doPostback to perform its postbacks, and thus all server-side links are disabled when JS is disabled.
 
So, I did a workaround, with a function that can modify an asp.net linkButton so that it will work – albeit in degraded mode when JS is disabled
 

public static void MakeNoJSSafe(LinkButton lb,string alternativeURL)

{

     string strJSLink = "javascript:__doPostBack(‘" + lb.ClientID + "’,”)";

     lb.Attributes.Add("onClick",strJSLink + ";this.href=’#’");

     lb.Attributes["href"] = alternativeURL;

     return;

}

 

For me, an hour of trial-and-error, for you, a minutes cut & paste.

Please credit me, if you use this script.

 

Categories: Uncategorized

Internet Voicemail service set live

Send Voicemail to landline phones using an web-based interface, check out www.sms-txt.co.uk/voicemail.aspx
 
The idea behind it, is to have an automated appointment reminder service, where organisations can post reminders on the website, and then at a scheduled time, a phone call will be made to that person, reminding him or her about their appointment.
 
Other applications could be service level notifications such as "Your water service will be cut off from 12 until 2 today" etc. – Or as identity verification for financial institutions.
 
Try it out!
 
 
 
Categories: Uncategorized