Archive
Export Google Search Results to CSV
{
GoogleSearchService.GoogleSearchService gss =
new GoogleSearchService.GoogleSearchService(); string CSV = ""; try{
for(int i=170;i<10000;i+=10){
GoogleSearchService.GoogleSearchResult gsr = gss.doGoogleSearch("L3Pyyh5QFHKU740wXUu0/aBu17loGATB",SearchString,0,10,
false,"",false,"","",""); foreach(GoogleSearchService.ResultElement reSearch in gsr.resultElements){
CSV += reSearch.title.Replace(",","").Replace("n","") + ",";
CSV += reSearch.snippet.Replace(",","").Replace("n","") + ",";
CSV += reSearch.URL.Replace(",","").Replace("n","") + "n";
}
Debug.Write("Progress:" + i.ToString());
}
}
catch(Exception ex){
Debug.Write(ex.ToString());
}
FileStream fsOut =
new FileStream(FileName,FileMode.Create);StreamWriter swOut =
new StreamWriter(fsOut);swOut.Write(CSV);
fsOut.Close();
}
Writing a C# Application without a user interface
public
System.Timers.Timer tmrPoll = new System.Timers.Timer();[STAThread]
static void Main(){
VoiceMailMain vmmInstance =
new VoiceMailMain();vmmInstance.tmrPoll.Enabled =
true;vmmInstance.tmrPoll.Interval = 5000;
vmmInstance.tmrPoll.Elapsed +=
newSystem.Timers.ElapsedEventHandler(vmmInstance.tmrPoll_Tick);
System.Threading.Thread.CurrentThread.Suspend();
}
public
void tmrPoll_Tick(object sender, System.Timers.ElapsedEventArgs e){ … and magic happens … }
Simple when you know how!
No mapping between account names and security IDs
Uploading a file via a web service
string
strPath = HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"].ToString(); string strFileName = (Guid.NewGuid()).ToString()+".wav";FileStream fsWave =
new FileStream(strPath + strFileName,FileMode.Create);fsWave.Write(WaveData,0,WaveData.Length);
fsWave.Close();
Where WaveData was my Byte array.
Then when consuming this service, from an ASP.NET page, I used this code
HttpPostedFile hpfWave =
this.AudioFile.PostedFile; int intFileLen = hpfWave.ContentLength; byte[] bWaveData = new byte[intFileLen];hpfWave.InputStream.Read(bWaveData, 0, intFileLen);
strMessage = vmWebService.UploadAudio(bWaveData);
Where AudioFile is my Input type=file on the web page, and vmWebService was my webservice.
If you’re interested in knowing where this is leading, check out www.sms-txt.co.uk in a few days!
SQL performance: Nested select statements.
Charset reverting to Windows standard
Differences between CHOICE command in Batch files
IF ERRORLEVEL == 3 GOTO LIVE
IF ERRORLEVEL == 2 GOTO BACKUP
IF ERRORLEVEL == 1 GOTO LOCAL
EXIT
set /p choice=Please choose a menu option.
if not ‘%choice%’==” set choice=%choice:~0,1%
if ‘%choice%’==’1’ goto LOCAL
if ‘%choice%’==’2’ goto BACKUP
if ‘%choice%’==’3’ goto LIVE
EXIT
Google Toolbar buttons… second attempt
http://toolbar.google.com/buttons/add?url=http%3A%2F%2Fwww.webtropy.com%2fw%2fbuymusiccd.xml
http://toolbar.google.com/buttons/add?url=http%3A%2F%2Fwww.webtropy.com%2fw%2ffindpeoplefreecouk.xml
Transparent Localisation
public static string getGetSiteCulture()
{
string strUrl = System.Web.HttpContext.Current.Request.Url.ToString().ToLower();
string strCulture = "en-GB";
if (strUrl.IndexOf("mensajetexto")!=-1) {strCulture = "es-ES";}
if (strUrl.IndexOf("handyspruche")!=-1) {strCulture = "de-DE";}
if (strUrl.IndexOf("envoyezsms")!=-1){strCulture = "fr-FR";}
return strCulture;
}
Then I have 4 different Resource files, strings.es-ES.resx, strings.en-GB.resx etc.
public static string Translate(string ID)
{
rmTranslations.IgnoreCase =
true;
string strTranslation ="";
Thread.CurrentThread.CurrentCulture =
new CultureInfo(getGetSiteCulture());
Thread.CurrentThread.CurrentUICulture =
new CultureInfo(getGetSiteCulture());
try
{strTranslation= rmTranslations.GetString(ID);}
catch{
throw new Exception(ID + " not found");
}
return strTranslation;
}
Then in place of static text, I put Translations.Translate("Whatever")
Parsing Skylights Route information
// var aVCE = new Array(‘TXL’,’HAM’,’HAJ’,’CGN’,’STR’, 0);
string[] strlines = Regex.Split(tbEntry.Text,@"n"); string strOutput = ""; foreach(string strLine in strlines){
string strFromIata = Regex.Match(strLine,@"a(w{3})s").Groups[1].Value;MatchCollection mcIatas = Regex.Matches(strLine,@"’w{3}’");
foreach(Match mIata in mcIatas){
strOutput+="’" + strFromIata + "’," + mIata.Value + "rn";
}
}
tbEntry.Text = strOutput;