Monday, December 29, 2008

Followup: IE6 PNG Alpha Transparency Fix

I, like many others, ran into the issue of <a> links not being click-able when they sit on top of an element upon which the alpha fix has been run.


A hint I got off of this site gave me the answer I was looking for: The element containing the filtered png must not have a position set, and the links within that element must have a position set.

Thursday, December 4, 2008

Vertically & Horizontally Centered <div>

Ran across this beautiful CSS example of a perfectly centered <div>:


#mydiv
{
position:absolute;
top: 50%;
left: 50%;
width:30em;
height:18em;
margin-top: -9em; /*set to a negative number 1/2 of your height*/
margin-left: -15em; /*set to a negative number 1/2 of your width*/
}

Wednesday, November 19, 2008

FTP/SSL through a NAT firewall

This was a helpful article in understanding connectivity issues when attempting to use FTPS through a NATed firewall:

http://geekswithblogs.net/Lance/archive/2005/08/23/50912.aspx

I'm using FileZilla Server to receive files from someone else and needed to set up FTPS. Specifying a particular port, and then opening that port, solved the problems I was having (i.e. 425 errors).

Monday, October 27, 2008

Using jQuery to make LI elements hover-able in IE6

Another necessary hack, this time to overcome IE6's non-support of the hover pseudo-class for LI elements.

This is to be used in situations where navigation is structured using UL, LI, and A elements and styled via CSS.  Please note that additional selectors will be required when implementing this solution: the standard selector (using li:hover notation) and the alternate selector (using li.over notation to support what this JavaScript is accomplishing):


$(document).ready(function() {
// Hack to make li's 'hover-able'
if (document.all && document.getElementById) {
$("#mainnav > .menu ul > li").each(function() {
this.onmouseover = function() { this.className += " over"; }
this.onmouseout = function() { this.className = this.className.replace(" over", ""); }
});
}
});

IE6 PNG alpha transparency solution

I know a bazillion solutions have been posted to the interwebs to solve this problem, but I wanted to make a note of one that I found to work quite well:

Thursday, September 25, 2008

JavaScript HTMLEncode function

Found this neat trick on another blog (http://lunarmedia.com/blogs/lunarmedia_blog/archive/2006/10/23/120405.aspx) to escape characters for presentation in HTML:

function escapeHTML (str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}; 

Thursday, September 18, 2008

IDIOTIC WebResource.axd workaround

I was tasked with moving an ASP.NET 3.5 website from one web server to another.  Everything worked great on the second server, except I was getting 404 errors anytime an embedded resource was requested with a WebResource.axd URL.

I went all over Google looking for the answer, and found a workaround that works, but is absolutely ridiculous:

Place an empty WebResource.axd file at the location that is 404'ing.

I'm sure this has something to do with HTTP handlers and priorities and the like, but whatever the real issue is, it is so obscure that I'm going to use this workaround for now and move on.

Ugh.

Friday, August 1, 2008

The remote certificate is invalid according to the validation procedure

I'm calling an ASP.NET web service from an ASP.NET web application. The two applications are on different servers. The web service requires SSL and presents the application with a self-signed certificate. Since this is an internal app, I want the client application to trust the web service and its self-signed cert.

There are lots of suggestions on how to do this in your code by coding a delegate method to accept all server certificates regardless of origin:

ServicePointManager.ServerCertificateValidationCallback =
delegate(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors) { return true; };
I don't want to do this, though, because this same code will be rolled out to production and it seems sloppy to me to allow all certificates to validate carte blanche.

So, I set out to download the internal SSL certificate and install it in the client computer's Trusted Root Certification Authorities cache. That still doesn't work!

Thanks to Ferry Onderwater's entry at http://www.arcencus.nl/Blogs/tabid/105/EntryID/39/Default.aspx, I see now where I went astray. By default, the Certificate snap-in installs certificates for the current user only. I needed all users to trust the certificate.

Solution:
  • Start a new MMC.
  • File --> Add/Remove Snap-In...
  • Click Add...
  • Choose Certificates and click Add.
  • Check the "Computer Account" radio button. Click Next.
  • Choose the client computer in the next screen. Click Finish.
  • Click Close.
  • Click OK.
  • NOW install the certificate into the Trusted Root Certification Authorities certificate store. This will allow all users to trust the certificate.

Tuesday, July 29, 2008

SharePoint: Errors 6482, 6398

The Event Log on our MOSS 2007 server was filled with alternating error codes 6482 and 6398.

6482:
Application Server Administration job failed for service instance Microsoft.Office.Server.Search.Administration.SearchServiceInstance (dc8cedfd-9340-42bb-adee-57e75040cdf6).

Reason: Retrieving the COM class factory for component with CLSID {3D42CCB1-4665-4620-92A3-478F47389230} failed due to the following error: 80070005.
...

6398:
The Execute method of job definition Microsoft.Office.Server.Search.Administration.IndexingScheduleJobDefinition (ID 66aead00-c73c-4e06-a1ce-ac86070bb9da) threw an exception. More information is included below.

Retrieving the COM class factory for component with CLSID {3D42CCB1-4665-4620-92A3-478F47389230} failed due to the following error: 80070005.
...

---

After a little bit of Google researching, I found that the service account used by the "Windows SharePoint Services Search" service did not have appropriate rights to launch, activate, and access the DCOM component oSearch.

Give the service account Local Launch and Local Activation permissions in the "Launch and Activation permissions" portion of the oSearch DCOM component properties dialog. Also, give the service account Local Access permissions in the "Access Permissions" portion of the properties. Save the changes and restart the "Windows SharePoint Services Search" service and you should be good to go.

Thanks to the folks at Tahoe Solutions for posting this on their blog: http://tahoesolutions.blogspot.com/2008/01/event-6482-and-6398-errors-in-event.html.

Thursday, July 24, 2008

Accessing subsites' lists via the MOSS 2007 Lists.asmx web service

I spent a little bit of time trying to figure this one out. I'm playing with the exposed web services that MOSS 2007 provides, trying to figure out how to manipulate lists via this API. My web reference is set to http://company.com/Clients/_vti_bin/Lists.asmx, but I am getting the same response as if the web reference were set to the site root (i.e. http://company.com/_vti_bin/Lists.asmx).

Thanks to user in.the.dark on MSDN forums (http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/80be9abc-f9e0-49b6-8ebc-8f90ddbf27a2/), a workaround is to set the URL programmatically, like so:

using (com.company.Lists lists = new com.company.Lists())
{
lists.Url = "http://company.com/Clients/_vti_bin/Lists.asmx";
XmlNode listColl = lists.GetListCollection();
}

listColl now contains the subsite's lists, rather than the root site's lists.

Monday, June 16, 2008

Calculating Work Days

I ran across the following T-SQL function to calculate the number of workdays between a given start date and end date. (This does not exclude non-weekend non-workdays such as holidays.)

Thanks to Jeff Moden for this function, which I found at http://www.sqlservercentral.com/articles/Advanced+Querying/calculatingworkdays/1660/:

SELECT
(DATEDIFF(dd, @StartDate, @EndDate) + 1)
-(DATEDIFF(wk, @StartDate, @EndDate) * 2)
-(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)

Thursday, June 12, 2008

ASP.NET Menu control & "downlevel" browsers

I ran into this fix when trying to get an ASP.NET 2.0 Menu control to render correctly on Safari. It turns out that ASP.NET thinks Safari is a downlevel browser (meaning incapable of rendering XHTML), so it sends a funky (and generally non-functioning) rendering of the Menu control down to the browser.

This isn't guaranteed to work in all cases, but in my case, adding the following Page directive did the trick:

<%@ Page ClientTarget="uplevel"... %>

Wednesday, June 11, 2008

Result set was not generated by a SELECT statement

This obscure error occurred when using PHP ODBC to retrieve values from a stored procedure. It turns out this occurs when the stored procedure SELECTs data from one or more TEXT columns. Convert these columns to VARCHAR(8000) and you're good to go.

Monday, June 9, 2008

AGONY: Vista Business x64 and SQL Server Management Studio

I have been fighting this one for days: my computer is currently joined to our corporate domain, but I am logged in as a local user. I've used "Manage network passwords" to add all of the relevant credentials for domain access. However, I still get the following error when logging in via Windows Authentication in SSMS:

Login failed for user ''. The user is not associated with a trusted SQL Server connection.

The error logs show that the SSPI handshake is failing - meaning that Windows is not passing along my valid domain credentials to SQL Server.

Finally, I found a workaround that deals with what I'm experiencing by making use of the runas command. It's hacky, and this is definitely due to Vista's "wonderful feature", but it gets the job done. Thanks to Jason Follas for the following tip:

http://www.jasonfollas.com/wiki/Default.aspx?Page=SQL%20Management%20Studio%20on%20Vista&AspxAutoDetectCookieSupport=1

For the record, we should not have to do this.

Wednesday, April 23, 2008

How to install Windows SharePoint Services 3.0 Tools to XP or Vista

Another blog ripoff, this time from Janne Mattila, on how to trick XP or Vista machines into thinking that WSS 3.0 is installed so that you can install WSS 3.0 Tools for Visual Studio 2005:

http://blogs.msdn.com/jannemattila/archive/2007/08/16/how-to-install-windows-sharepoint-services-3-0-tools-to-xp-or-vista.aspx

Details: it's a registry hack...

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0]
"Sharepoint"="Installed"

Tuesday, April 22, 2008

How to Create a MOSS 2007 VPC Image

Wonderful series of posts by Tony Zink outlining exactly what you need to do to set up Microsoft Office SharePoint Server 2007 on a Virtual PC with a SQL Server 2005 backend and full e-mail capabilities:

http://www.pptspaces.com/sharepointreporterblog/Lists/Posts/Post.aspx?ID=28

Thursday, April 3, 2008

LINQ to SQL and the DataGridView control

A DataGridView control won't bind directly to an IEnumerable object, so two options are:

1. Create a BindingSource, set its DataSource to the IEnumerable object, then set the DataGridView.DataSource property to the BindingSource.

2. Bind the DataGridView.DataSource property to the IEnumerable object's ToList() method.

Thanks to Ken Tucker on Microsoft Forums for this tip.

Monday, March 3, 2008

How to resolve "__doPostBack is not defined" error

Thanks to Julien Pinquié:

When I ran across this, I found that I'd closed a <script> tag referring to an external .js file with /> notation instead of <script></script>; the <script> tag doesn't accept this notation for whatever reason.

Sunday, February 17, 2008

Simple Port Scan

The following function will check to see if connectivity is enabled for a particular host on a particular port via TCP/IP:

Function ScanPort(ByVal strHost As String, ByVal intPort As Integer) As Boolean
    Dim aobjIPs() As System.Net.IPAddress = System.Net.Dns.GetHostEntry(strHost).AddressList
    If aobjIPs.Length > 0 Then
        Dim objEndpoint As New System.Net.IPEndPoint(aobjIPs(0), intPort)
        Using s As New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
            Try
                s.Connect(objEndpoint)
                Return s.Connected
            Catch ex As Exception
                Return False
            End Try
        End Using
    Else
        Return False
    End If
End Function

Thursday, January 31, 2008

JavaScript button disable with postback

When an ASP.NET server-side button is given client-side JavaScript code to execute when handling onclick, the button no longer posts back by default. However, there is a small piece of code you can add to the onclick attribute of the button to re-enable the postback behavior.

Adding this code in the Page_Load method will remove a server-side button's postback call:

btnConfirm.Attributes.Add("onclick", "Confirm_Click();")

But writing the code like this will reinstate the postback call:

btnConfirm.Attributes.Add("onclick", "Confirm_Click(); " + ClientScript.GetPostBackEventReference(btnConfirm, ""))

FileUpload control in an UpdatePanel

By nature, FileUpload controls require an entire page postback to submit the file contents, so they are explicitly excluded from support within an UpdatePanel...however, if you put the Submit button that performs the postback intended to upload the file into a PostbackTrigger, you can place your FileUpload control within the UpdatePanel.


<asp:UpdatePanel runat="server">
    <ContentTemplate>
        <asp:FileUpload runat="server" ID="fupTest" />
        <asp:Button runat="server" ID="btnSubmit" Text="Upload"/>
    </ContentTemplate>
    <Triggers>
        <asp:PostBackTrigger ControlID="btnSubmit" />
    </Triggers>
</asp:UpdatePanel>

Wednesday, January 9, 2008

Transactions and strongly typed TableAdapters

To do this, create a new class file containing a Partial Class declaration with the name of your table adapter. Add this code to the class:


Private _transaction As SqlTransaction

Private Property Transaction() As SqlTransaction
Get
Return Me._transaction
End Get
Set(ByVal Value As SqlTransaction)
Me._transaction = Value
End Set
End Property

Public Sub BeginTransaction()
' Open the connection, if needed
If Me.Connection.State <> ConnectionState.Open Then
Me.Connection.Open()
End If
' Create the transaction and assign it to the Transaction property
Me.Transaction = Me.Connection.BeginTransaction()
' Attach the transaction to the Adapters
For Each command As SqlCommand In Me.CommandCollection
command.Transaction = Me.Transaction
Next
Me.Adapter.InsertCommand.Transaction = Me.Transaction
Me.Adapter.UpdateCommand.Transaction = Me.Transaction
Me.Adapter.DeleteCommand.Transaction = Me.Transaction
End Sub

Public Sub CommitTransaction()
' Commit the transaction
Me.Transaction.Commit()
' Close the connection
Me.Connection.Close()
End Sub

Public Sub RollbackTransaction()
' Rollback the transaction
Me.Transaction.Rollback()
' Close the connection
Me.Connection.Close()
End Sub