A friend brought her laptop round to mine yesterday, as after xp had done an update and installed xp sp3, the wireless was showing as connected, but no page would load. When wired in, all was fine.
I tried connecting it to my WPA enabled network, and all was fine. After googlin the problem, I found that there were some issues that some people had had with WPA after xp sp3, but not with WEP - in fact, they were recommending switching to WEP (Not a good idea).
Anyway, I did the alternative, changed their laptop and belkin router over to wpa2 psk, and it's fine now!
Monday, 5 January 2009
Wednesday, 17 December 2008
Javascript parseInt, parseFloat, decide on data type
I was facing an issue today whereby I need to accept a value from an input control, but not knowing what it contained - i.e. a number, a floating point number (decimal) or a string, but I needed to perform maths on it.
With some help of some friends over at forums.asp.net, I came up with the following. You pass it your value, and it will send back the right data type to use on mathematical operations like "+" which normally concatenates strings instead of adding numbers as strings.
function parseValues(aValue)
{
if(isNaN(aValue))
{
return aValue;
}
else
{
if(aValue.indexOf(".")>0)
{
return parseFloat(aValue);
}
else
{
return parseInt(aValue);
}
}
}
With some help of some friends over at forums.asp.net, I came up with the following. You pass it your value, and it will send back the right data type to use on mathematical operations like "+" which normally concatenates strings instead of adding numbers as strings.
function parseValues(aValue)
{
if(isNaN(aValue))
{
return aValue;
}
else
{
if(aValue.indexOf(".")>0)
{
return parseFloat(aValue);
}
else
{
return parseInt(aValue);
}
}
}
Wednesday, 10 December 2008
ScriptResource.axd - if(!a._events) error
I was getting this error today, for some unknown reason, and obviously debugging it is of no use, as the brightspark that declared everything as "a", "b" or "c" obviously didn't want us to!
Anyway, after some searching around on my page, I found that a modalpopupextender that I have added to my page, had an invalidad cancelcontrolid, I had mis-spelled it, and therefore this error must be because "a" in this instance was the control that was to be used to close (cancel) the popup.
The joys of using other peoples code....
Anyway, after some searching around on my page, I found that a modalpopupextender that I have added to my page, had an invalidad cancelcontrolid, I had mis-spelled it, and therefore this error must be because "a" in this instance was the control that was to be used to close (cancel) the popup.
The joys of using other peoples code....
Thursday, 6 November 2008
ASP Buttons not firing events
How stupid did I feel today? Very, that's what.
In my perfectly working application, I add a new tab to the tabcontainer, and add some link buttons in it, but when running, the buttons would not work - they wouldn't run the code behind - I was completely perplexed as to why this was happening.
Eventually a colleague said to me "are you using the CausesValidation" - AH!!! Somewhere else on the application there is a requiredfieldvalidator, and that was telling the page that navigation couldn't take place, but the field was required - but in this case, it was allowed to happen. So, setting the property of CausesValidation = false, solved the problem.
In my perfectly working application, I add a new tab to the tabcontainer, and add some link buttons in it, but when running, the buttons would not work - they wouldn't run the code behind - I was completely perplexed as to why this was happening.
Eventually a colleague said to me "are you using the CausesValidation" - AH!!! Somewhere else on the application there is a requiredfieldvalidator, and that was telling the page that navigation couldn't take place, but the field was required - but in this case, it was allowed to happen. So, setting the property of CausesValidation = false, solved the problem.
Wednesday, 5 November 2008
Sothink DHTML fails to install on DHTMLmenu.dll
I've had this problem twice now, and here's how I got round it to make it work under win xp sp2.
Start the installation, when it fails to register the file, click ignore. The installation will complete, but the program won't work.
Start the uninstall for it, again it will hang. Go into task manager, and kill the uninstall process. A temp file is produced, so kill that process also (it's the only one beginning with _tmp).
Do the install again, and it works!
Start the installation, when it fails to register the file, click ignore. The installation will complete, but the program won't work.
Start the uninstall for it, again it will hang. Go into task manager, and kill the uninstall process. A temp file is produced, so kill that process also (it's the only one beginning with _tmp).
Do the install again, and it works!
Monday, 20 October 2008
AJAX NumericUpDown extender hides textbox
I couldn't for the life of me figure out why my nicely styled textbox was being hidden when I added an numeric up down extender to it.
The reason, you have to explicitly add a width attribute to the extender so that it knows how big the parent box is!
The reason, you have to explicitly add a width attribute to the extender so that it knows how big the parent box is!
Friday, 19 September 2008
Comparing two files, one on a hard drive, and one from a web site
In my quest to create an effective and lean search engine service for the company I work for, I used to crawl all of our websites and download every file from them, and write them to a local cache. When the cache was detected as updated, my indexing system (based on Lucene.Net) detects the changes, and reindexes those sites.
You may well be able to imagine, that with over 800 sites, this is an awfully large amount of data to writing to the cache, and then an even bigger job for the index to reindex all these files!
So, what I wanted was a mechanism whereby I could compare the local copy, to a streamed copy of the file from the server into the local memory, and see there were any changes.
To do this, I immediate thought of looking for something like a checksum check, but a colleague recommended looking at doing a MD5 hash on them, using a tool like CipherLite by Obivex. Looking into this, i found an easier way, by using a webrespone to download a memory stream, opening the local file using a filestream, and performing hash on them to see whether the contents were the same:
//get a memory stream to hold the data that is downloaded
MemoryStream msFile = new MemoryStream();
writer = new BinaryWriter(msFile);
byte[] RecvBuffer = new byte[10240];
int nBytes, nTotalBytes = 0;
// loop to receive response buffer
while((nBytes = response.socket.Receive(RecvBuffer, 0, 10240, SocketFlags.None)) > 0)
{
// increment total received bytes
nTotalBytes += nBytes;
// write received buffer to file
writer.Write(RecvBuffer, 0, nBytes);
// check if the uri type not binary to can be parsed for refs
if(bParse == true)
// add received buffer to response string
strResponse += Encoding.ASCII.GetString(RecvBuffer, 0, nBytes);
// update view text
// check if connection Keep-Alive to can break the loop if response completed
if(response.KeepAlive && nTotalBytes >= response.ContentLength && response.ContentLength > 0)
break;
}
bool bContinue = false;
FileStream fStream = null;
try
{
//check to see if the file exists on the local file system
if(File.Exists(PathName))
{
//open the file, and read in the stream
fStream = File.Open(PathName, FileMode.Open,FileAccess.Read,FileShare.Read);
//compare the two streams, to see if they are the same (see later)
bContinue = compareFiles(msFile,fStream);
}
else
{
//file doesn't exist, download anyway
bContinue = true;
}
}
catch(Exception ex)
{
bContinue = true;
LogError(ex.Message,"");
}
finally
{
if(fStream!=null)
fStream.Close();
fStream = null;
}
if(bContinue)
{
//create a stream to create the new file
streamOut = File.Open(PathName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
//create the new copy
msFile.WriteTo(streamOut);
//close up
streamOut.Close();
}
msFile.Close();
So, to how the streams are compared. I adapted my solution to one I found via a google search on hashing:
bool compareFiles(MemoryStream file1, FileStream file2)
{
using (HashAlgorithm hashAlg = HashAlgorithm.Create())
{
// Calculate the hash for the files.
byte[] hashBytesA = hashAlg.ComputeHash(file1);
byte[] hashBytesB = hashAlg.ComputeHash(file2);
// Compare the hashes.
if (BitConverter.ToString(hashBytesA) == BitConverter.ToString(hashBytesB))
{
//they are the same
return true;
}
else
{
//they are different
return false;
}
}
}
Hope this helps.
You may well be able to imagine, that with over 800 sites, this is an awfully large amount of data to writing to the cache, and then an even bigger job for the index to reindex all these files!
So, what I wanted was a mechanism whereby I could compare the local copy, to a streamed copy of the file from the server into the local memory, and see there were any changes.
To do this, I immediate thought of looking for something like a checksum check, but a colleague recommended looking at doing a MD5 hash on them, using a tool like CipherLite by Obivex. Looking into this, i found an easier way, by using a webrespone to download a memory stream, opening the local file using a filestream, and performing hash on them to see whether the contents were the same:
//get a memory stream to hold the data that is downloaded
MemoryStream msFile = new MemoryStream();
writer = new BinaryWriter(msFile);
byte[] RecvBuffer = new byte[10240];
int nBytes, nTotalBytes = 0;
// loop to receive response buffer
while((nBytes = response.socket.Receive(RecvBuffer, 0, 10240, SocketFlags.None)) > 0)
{
// increment total received bytes
nTotalBytes += nBytes;
// write received buffer to file
writer.Write(RecvBuffer, 0, nBytes);
// check if the uri type not binary to can be parsed for refs
if(bParse == true)
// add received buffer to response string
strResponse += Encoding.ASCII.GetString(RecvBuffer, 0, nBytes);
// update view text
// check if connection Keep-Alive to can break the loop if response completed
if(response.KeepAlive && nTotalBytes >= response.ContentLength && response.ContentLength > 0)
break;
}
bool bContinue = false;
FileStream fStream = null;
try
{
//check to see if the file exists on the local file system
if(File.Exists(PathName))
{
//open the file, and read in the stream
fStream = File.Open(PathName, FileMode.Open,FileAccess.Read,FileShare.Read);
//compare the two streams, to see if they are the same (see later)
bContinue = compareFiles(msFile,fStream);
}
else
{
//file doesn't exist, download anyway
bContinue = true;
}
}
catch(Exception ex)
{
bContinue = true;
LogError(ex.Message,"");
}
finally
{
if(fStream!=null)
fStream.Close();
fStream = null;
}
if(bContinue)
{
//create a stream to create the new file
streamOut = File.Open(PathName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
//create the new copy
msFile.WriteTo(streamOut);
//close up
streamOut.Close();
}
msFile.Close();
So, to how the streams are compared. I adapted my solution to one I found via a google search on hashing:
bool compareFiles(MemoryStream file1, FileStream file2)
{
using (HashAlgorithm hashAlg = HashAlgorithm.Create())
{
// Calculate the hash for the files.
byte[] hashBytesA = hashAlg.ComputeHash(file1);
byte[] hashBytesB = hashAlg.ComputeHash(file2);
// Compare the hashes.
if (BitConverter.ToString(hashBytesA) == BitConverter.ToString(hashBytesB))
{
//they are the same
return true;
}
else
{
//they are different
return false;
}
}
}
Hope this helps.
Subscribe to:
Posts (Atom)