Thursday, March 26, 2009

Disabling Hibernation in Vista

If you never use hibernation in Vista, you may want to just turn off the feature and save the room that the hiberfil.sys file creates on your hard drive. If you have 4GB of memory like I do, that means saving 4GB of disk space when you disable hibernation.

Here’s how you do it:

Run the command, powercfg –h off to disable hibernation. I had to use elevated permissions to do this on my system.

To re-enable hibernation run the command, powercfg –h on

That’s all there is to it and you now have some extra drive space.

Tuesday, March 10, 2009

How to determine if your webpart is providing for others

In my continuation with my webpart for connecting two SPGridViews together I came across the need to determine if the current instance of the part was actually providing for any other webparts. The reason I need to know this is because I wanted to render the first column as a select link if it was providing to another part, but otherwise just render as a standard datacolumn.

Here is the solution I came up with:

 Private Function IsProviding() As Boolean
For Each c As WebPartConnection In Me.WebPartManager.Connections
If c.Provider Is Me Then
Return True
End If
Next
Return False
End Function
Does anyone have another way to determine this?
 



Configuring a SharePoint WebPart as both a Consumer and Provider for the same interface

Recently I’ve been coding a web part that shows a sql query inside a SPGridView and wanted to set it up so it could be a connection provider (ConnectionProvider) as well as a connection consumer (ConnectionConsumer).

For some reason, when I set it up this way the Connections menu used to configure the inbound and outbound connections was greyed out when I had both, but worked if I commented out either one.

It seems that there is an optional argument named “id” for both the ConnectionProvider and ConnectionConsumer decorators and when I provided this argument it started working. It seems there is a default id if you don’t specify it and they must have the same default id.

My code now looks something like this:

#Region "IWebPartRow Provider"
<ConnectionProvider("RowProvider", "DataViewRowProvider")> _
Public Function GetConnectionInterface() As IWebPartRow
Return New DataViewWebPart()
End Function

Public Sub GetRowData(ByVal callback As RowCallback) _
Implements IWebPartRow.GetRowData
callback(oGrid.SelectedRow)

End Sub

Public ReadOnly Property Schema() As _
ComponentModel.PropertyDescriptorCollection Implements IWebPartRow.Schema
Get
Return TypeDescriptor.GetProperties(oView)
End Get
End Property
#End Region
#Region "IWebPartRow Consumer"
<ConnectionConsumer("Row", "DataViewRowConsumer")> _
Public Sub SetConnectionInterface(ByVal provider As IWebPartRow)
_provider = provider
End Sub

#End Region