Friday, June 19, 2009
FTP.exe on Windows 7
Thursday, May 14, 2009
Tweeting real time energy usage
Andrew
Tuesday, December 02, 2008
CRM 4.0 Get accountid from Customer Name (account name)
Use it like this :-
string accountid = GetAccountId("My Company Name");
private string GetAccountID (string customername)
{
string ret = "";
// Query condition
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "name";
condition.Operator = ConditionOperator.Equal;
condition.Values = new object[1];
condition.Values[0] = customername;
// FilterExpression
FilterExpression filterPrincipal = new FilterExpression();
filterPrincipal.FilterOperator = LogicalOperator.And;
filterPrincipal.Conditions = new ConditionExpression[] { condition };
// Columns to return
ColumnSet columns = new ColumnSet();
columns.Attributes = new string[] { "accountid" };
// Query Contact
QueryExpression Query = new QueryExpression();
Query.EntityName = EntityName.account.ToString();
Query.ColumnSet = columns;
Query.Criteria = filterPrincipal;
// Get entities
BusinessEntityCollection entities = (BusinessEntityCollection) CrmService.RetrieveMultiple (Query);
foreach (BusinessEntity entity in entities.BusinessEntities)
{
account Account = entity as account;
return Account.accountid.Value.ToString();
}
return "";
}
Thursday, September 11, 2008
Virtual PC 2007 Version numbers
Virtual PC 2007 SP1 = Version 6.0.192.0
SQL 2008 Error 5120
SMTP server in Windows Server 2008
Tuesday, September 02, 2008
PopupControlExtender bug with buttons
Sunday, August 31, 2008
IIS7 folder rights when uploading files
IIS7 Membership provider
Originally I had this in my web.config file :-
< defaultprovider="MyMembershipProvider">
<>
< name="MyMembershipProvider" connectionstringname="MyMembershipConnectionString" type="System.Web.Security.SqlMembershipProvider" applicationname="MyAppName" enablepasswordretrieval="false" enablepasswordreset="true" requiresquestionandanswer="true" requiresuniqueemail="true" passwordformat="Hashed">
< /add >
< /providers >
< /membership >
But I discovered that this works as a membership provider but does not allow IIS Manager to display the users when the .NET Users button is clicked. If you replace the type attribute above with :-
type="System.Web.Security.SqlMembershipProvider,System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"
it works.
Wednesday, August 27, 2008
iPhone 3G - Useless
It's also really annoying that the mail application cannot be rotated and where is the copy & paste functionality? I understand copy & paste is a security issue but surely it’s an essential feature.
Overall : not at all impressed.
Wednesday, July 09, 2008
Good quote...
Thursday, June 12, 2008
Adding OpenID to an existing ASP.NET application
[Updated 22:00 12 June 2008] To include improvements suggested by Andrew Arnott.
In this post I'll describe the steps I took to add OpenID support to an existing ASP.NET app that used forms authentication. The application originally used the users email address as their username. The OpenID login process therefore needs to provide an email address to avoid having to rewrite loads of code. Not all OpenID providers allow email addresses to be sent so new users might have to partially re-register the first time they use their OpenID.
- Downloaded the latest DotNetOpenID zip file from http://dotnetopenid.googlecode.com/files/
- Unziped the package
- Copied and renamed login.aspx and login.cs from \Samples\RelyingPartyPortal to my project's root folder, renaming them loginOpenID.aspx and loginOpenID.cs. Changed codebehind attribute in loginOpenID.aspx from CodeBehind="login.aspx.cs" to CodeBehind="loginOpenID.aspx.cs". I then added a link named "Login with OpenID" on my original login.aspx page pointing to the new loginOpenID.aspx page. I then changed some of the properties on the OpenIdLogin control as I wanted to ask the OpenID provider to supply the users FullName and Email address. Unfortunately some providers (eg Yahoo.com) do not allow the FullName & Email info to be sent so we'll have to deal with this in code later.
<RP:OpenIdLogin ID="OpenIdLogin1"
runat="server"
RequestFullName="Require"
RequestEmail="Require"
RememberMeVisible="True"
PolicyUrl="~/PrivacyPolicy.aspx"
TabIndex="1"
OnLoggedIn="OpenIdLogin1_LoggedIn"
OnCanceled="OpenIdLogin1_Canceled"
OnFailed="OpenIdLogin1_Failed"
OnSetupRequired="OpenIdLogin1_SetupRequired" RememberMe="True"
/>
- Copied \Samples\RelyingPartyPortal\Code\state.cs to my project's App_Code folder
- Copied \Samples\RelyingPartyPortal\xrds.aspx to my project's root folder. Modified this file to point to my new loginOpenID.aspx page changing
<URI><%=new Uri(Request.Url, Response.ApplyAppPathModifier("~/login.aspx"))%></URI>
to
<URI><%=new Uri(Request.Url, Response.ApplyAppPathModifier("~/loginopenid.aspx"))%></URI>
- Copied \Samples\RelyingPartyPortal\privacypolicy.aspx to my project's root folder.
- I added the following to default.aspx (the default document for this domain).
<%@ Register Assembly="DotNetOpenId" Namespace="DotNetOpenId" TagPrefix="openid" %>
<openid:XrdsPublisher runat="server" XrdsUrl="~/xrds.aspx" />
This was required to get myopenid.com accounts to work. - Added a reference to the DotNetOpenID.dll from the \Samples\RelyingPartyPortal\bin folder
- I then added code to OpenIdLogin1_LoggedIn in loginOpenID.cs to ensure we have the user's real email address. If for whatever reason we cannot get their email address redirect them to the partially populated registration page.
protected void OpenIdLogin1_LoggedIn (object sender, OpenIdEventArgs e)
{
State.ProfileFields = e.ProfileFields;
// Setup linq connection to SQL database
DataClassesDataContext db = new DataClassesDataContext(ConfigurationManager.ConnectionStrings["DB_RW"].ConnectionString);
People people = null;
// See if user has logged on using OpenID before
try
{
people = (from c in db.Peoples
where c.OpenID == e.ClaimedIdentifier.ToString()
select c).Single();
}
catch
{
}
if (people == null)
{
// This is the first time this OpenID identity has been used
if (e.ProfileFields.Email == null)
{
// Force user to register as their OpenID provider did not send their email
// address (eg Yahoo.com) and this app needs their real email address.
e.Cancel = true;
Response.Redirect("RegisterNewAccount.aspx?mode=OpenID_NoEmailSupplied");
return;
}
else
{
// See if user has created an account already
try
{
people = (from c in db.Peoples
where c.Email == e.ProfileFields.Email
select c).Single();
}
catch
{
// email address does not exist in our user table redirect user
// to registration page.
e.Cancel = true;
Response.Redirect("RegisterNewAccount.aspx?mode=OpenID_UnknownEmail");
return;
}
}
}
if (people.Status.StartsWith("Reject T&C"))
{
e.Cancel = true;
loginFailedLabel.Text = "Your account has been suspended because you have rejected our T&C's.";
loginFailedLabel.Visible = true;
return;
}
if (people.Status != "Verified")
{
e.Cancel = true;
loginFailedLabel.Text = "Your account has not been verified yet. Check your email for further instructions.";
loginFailedLabel.Visible = true;
return;
}
// Remember OpenID identity for next time
people.OpenID = e.ClaimedIdentifier.ToString();
people.LoginCount = (people.LoginCount ?? 0) + 1;db.SubmitChanges();
// I set some other Session variables here
Session["UserEmail"] = people.Email;
// The openID code will now redirect to the requesting page
// and set context.user.identity.name to the OpenID identity
// eg http://andrew.jones.myopemid.com
}
- The RegisterNewAccount.aspx pre-populates as much information as it can. Any additional user information sent by the OpenID provider is available in State.ProfileFields.
Thursday, June 05, 2008
DataGridViewRow SelectedRows selection order
Here is a function to sort the list
// Create a generics list to hold selected rows so it can be sorted later
List<DataGridViewRow> SelectedRows = new List<DataGridViewRow>();
foreach (DataGridViewRow dgvr in yourDataGridViewControl.SelectedRows)
SelectedRows.Add(dgvr);
// Sort list based on DataGridViewRow.Index
SelectedRows.Sort (DataGridViewRowIndexCompare);
private static int DataGridViewRowIndexCompare (DataGridViewRow x, DataGridViewRow y)
{
if (x == null)
{
if (y == null)
{
// If x is null and y is null, they're
// equal.
return 0;
}
else
{
// If x is null and y is not null, y
// is greater.
return -1;
}
}
else
{
// If x is not null...
//
if (y == null)
// ...and y is null, x is greater.
{
return 1;
}
else
{
// ...and y is not null, compare the
// lengths of the two strings.
//
int retval = x.Index.CompareTo (y.Index);
if (retval != 0)
{
// If the strings are not of equal length,
// the longer string is greater.
//
return retval;
}
else
{
// If the strings are of equal length,
// sort them with ordinary string comparison.
//
return x.Index.CompareTo(y.Index);
}
}
}
}
Monday, June 02, 2008
Friday, May 09, 2008
LinkedIn BICSI RCDD group
http://www.linkedin.com/e/gis/101866/2861405DDA38
Tuesday, February 19, 2008
WPF Limit number of lines in multi line TextBox
XAML
<TextBox Height="138" Name="textBox_DeliverFrom" Width="257" AcceptsReturn="True" PreviewKeyDown="textBox_DeliverFrom_PreviewKeyDown" />
C#
private void textBox_DeliverFrom_PreviewKeyDown (object sender, KeyEventArgs e)
{
// Do not allow more than 8 Lines
if (e.Key == Key.Enter)
{
if (textBox_DeliverFrom.LineCount > 7)
e.Handled = true;
}
}
One needs to add a PreviewKeyDown handler and ignore then Enter key if the control has reached the required limit.
Tuesday, November 06, 2007
Installing msi on Vista without UAC prompts
Msiinfo.exe allows you to modify a msi file. In the example below I'm setting a flag to indicate that the msi file does not need to UAC prompt. This flag is only read when the file is installed on Vista.
I've added the following PostBuildEvents to the VS2005 Deployment project.
rem ----------------------------------------------------------
rem First set flag to indicate no UAC on Vista
rem ----------------------------------------------------------
"C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\msiinfo" "$(BuiltOuputPath)" -w 10
rem ----------------------------------------------------------
rem Code sign the msi file
rem ----------------------------------------------------------
"C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\signtool.exe" sign /f "$(ProjectDir)CodeSignKey.pfx" /p mypassword /d "Product Name" /du "http://www.productURL" /t "http://timestamp.comodoca.com/authenticode" "$(BuiltOuputPath)"
rem ----------------------------------------------------------
rem Code sign the setup.exe file
rem ----------------------------------------------------------
"C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\signtool.exe" sign /f "$(ProjectDir)CodeSignKey.pfx" /p mypassword /d "Product Name" /du "http://www.productURL" /t "http://timestamp.comodoca.com/authenticode" "setup.exe"
msiinfo.exe is available in the Windows SDK Components for Windows Installer Developers.
signtool.exe is available in the Microsoft Visual Studio 2005/.NET Framework 2.0
CodeSignKey.pfx is a code signing certificate. I bought mine from http://www.instantssl.com/code-signing/code-signing.html. This file must be manually exported from Internet Explorer 7 if you used Vista to purchase a code signing certificate. In this example i've put the pfx file in the same folder as the project .vdproj file.
mypassword is the password used when exporting the CodeSignKey.pfx from Internet Explorer. When you buy a code signing certificate using Vista it gets automatically installed into your Personal Certificates store in Internet Explorer. This article describes how to export this certificate so it can be used by SignTool. http://www.tech-pro.net/export-to-pfx.html
product name is the name of your installer. This is displayed along with the company name when you execute setup.exe
http://www.productURL is a url that can be used to get more info on the product
http://timestamp.comodoca.com/authenticode is the url of the Comodo time server. Certificates are valid for one year so it's important to time stamp the file when it is created. This allows the file to be protected for ever. If the file was not time stamped it would stop running when the certificate expired.
When installing on Vista launch the .msi file without using setup.exe. Any program called setup.exe automatically UAC prompts on Vista wiping out all the good work above.
Once you have done all this you can launch the msi file and not have to worry about it UAC prompting. In a corporate enviromnent it is a real pain to have to enter an admin password whenever someone wants to install a program. Preventing UAC when it is not required makes the process much easier.
Sunday, October 14, 2007
Vista start-up crash solved
Ever since I installed Vista on my Sony VGN-AR21S it has randomly crashed about every third re-boot. Task Manager would show the 'system' process using 98-100% processor utilisation. After about 10 minutes all 2Gb of memory would get used up and Vista would crash with a BSOD, typically a kernel in page error. I partially solved this problem by hibernating rather than shutting down the machine. I think I have now solved the problem.
I downloaded the excellent Sysinternals Process Monitor (http://www.microsoft.com/technet/sysinternals/default.mspx) which provides a full display of the individual executables running as part of the system process. Process Monitor showed that ndis.sys!NdisInitializeWrapper was consuming all the processor time and memory. This information indicated a network driver problem.
The machine has an Intel Pro 100/VE Ethernet card and an Intel Wireless 3945ABG Wi-Fi card. I downloaded the latest network drivers from the Intel web site and installed them. I then used device manager to delete both network devices. Device manager then re-detected both network cards. Having done this the machine appears to start-up without any problems.
It's really annoying that neither the Microsoft nor Sony update sites offer these new network drivers.
Wednesday, August 22, 2007
3Com V3000 ATA Ringing on UK Phones

A UK PSTN Full Master contains a capacitor, resistor and spark suppressor. If you use anything other than a PSTN Master you can use the phone to make calls but it will not ring.
There are many different PSTN Masters available with different pinouts. I have sucessfully tested the following Krone part:-
Krone P/N : 6536/1/601/11
3Com 4500 default admin password
So far I'm not impressed with the quality of documentation from 3Com.
