You are hereProgramming & Web Design / .Net


.Net

warning: Creating default object from empty value in /home/hagrinad/public_html/modules/taxonomy/taxonomy.pages.inc on line 33.

.Net information

SharePoint v3: Quick Launch Update

By hagrin - Posted on 02 May 2007

Just a FYI to the 3 of you reading this site (Hi Mom and Dad!), I made an update to the Recreating the SharePoint Quick Launch story I posted back in February. I made some code fixes that were mainly introduced with the release of the 40 Free WSS Application Templates made by Microsoft.

Hope the bug fixes help!

withEvents variable Header conflicts with property ... Error

By hagrin - Posted on 26 March 2007

Today, as I was converting some web applications from .Net 1.1 to .Net 2.0 I received the following error on the source pages of most of my ASPX pages -

withEvents variable 'Header' conflicts with property 'Header' in the base class 'Page' and should be declared 'Shadows'

Huh? That's what I said. However, the fix is relatively easy. What the error message is saying is that you probably have some element in your HTML code/script that has a value of "ID=Header". By giving this element a new ID name, the error message will be resolved.

SharePoint v3: tp_DeleteTransactionID

By hagrin - Posted on 25 February 2007

When working with SharePoint v3 list data, it's important to understand the data structure used to store list items. List data is stored in the AllUserData table and the name should be your first indication that you might run into a problem if trying to pull or manipulate data stored in this table. Why? Well, "all" user data is stored in that table including deleted data and you will need to know how to filter out deleted items and that is where the tp_DeleteTransactionID column comes into focus.

The tp_DeleteTransactionID column is a varbinary field so you cannot readily read the contents of that column in SQL Server Enterprise Manager. This coulmn acts as a "deleted flag" and you will need to be able to know what items you have removed from your list, but you forgot to remove from your Recycle Bin. List items that you delete from your list, but that remain in your Recycle Bin will have the value of the tp_DeleteTransactionID column updated from the default value of 0x. Once you remove the items from your Recycle Bin, the item's corresponding rows will be deleted from the AllUserData, but until you do so those item's rows will remain in the AllUserData table.

So, if you want to filter out deleted content for the purpose of data manipulation or transformation, but you don't want to have to worry that the user has remembered to empty the Recycle Bin, add the following WHERE clause to your SQL statements -

WHERE tp_DeleteTransactionID = 0x

Notice, that the value 0x is not surrounded by value defining apostrophes since the value is not a true string, numeric, date, etc. value, but a hex representation for the varbinary field.

SharePoint v3: Exception of type Microsoft.Sharepoint.WebPartPages.WebPartUserException was thrown Error

By hagrin - Posted on 15 February 2007

Today, I encountered an error that I wasn't immediately sure how to fix while creating a new web part. After uploading the .DWP file to the web part gallery, I attempted to add the web part to a recently created web part page. Even though I had a Try/Catch/Finally wrapper around my code, I received a browser alert that had the following error:

Exception of type Microsoft.Sharepoint.WebPartPages.WebPartUserException was thrown

After a very quick search for that error on Google's main search index and Google Groups, I found zero results. Then, I remembered that I didn't make the necessary corrections to the .DWP file - in particular, I left the Assembly field blank. After adding the correct assembly name, I saved the file, deleted the previously uploaded DWP file, re-uploaded the new DWP file and was able to successfuly add the web part. Success!

VB.Net - How to Unlock a Domain Account in Active Directory

By hagrin - Posted on 09 February 2007

How to Unlock a Domain Account in Active Directory utilizing Visual Basic .Net - (note: you must have Domain Admin privledges to execute this code successfully and you must import the System.DirectoryServices namespace):

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim strError As String
Try
Dim child As New System.DirectoryServices.DirectoryEntry("LDAP://DC=YourDomainsName,DC=com")
Dim searcher As New DirectorySearcher(child)
Dim result As SearchResult
Dim userEntry As DirectoryEntry
searcher.Filter = "(SAMAccountName=TheUsernameYouWantDisabled)"
searcher.CacheResults = False
result = searcher.FindOne
userEntry = result.GetDirectoryEntry
With userEntry
userEntry.Properties("LockOutTime").Value = 0
End With
userEntry.CommitChanges()
Catch ex As Exception
strError = ex.ToString
End Try

End Sub

VB.Net - How to Disable a Domain Account in Active Directory

By hagrin - Posted on 09 February 2007

How to Disable a Domain Account in Active Directory utilizing Visual Basic .Net - (note: you must have Domain Admin privledges to execute this code successfully and you must import the System.DirectoryServices namespace):

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim strError As String
Try
Dim child As New System.DirectoryServices.DirectoryEntry("LDAP://DC=YourDomainsName,DC=com")
Dim searcher As New DirectorySearcher(child)
Dim result As SearchResult
Dim userEntry As DirectoryEntry
searcher.Filter = "(SAMAccountName=TheUsernameYouWantDisabled)"
searcher.CacheResults = False
result = searcher.FindOne
userEntry = result.GetDirectoryEntry
With userEntry
userEntry.NativeObject.accountdisabled = True
End With
userEntry.CommitChanges()
Catch ex As Exception
strError = ex.ToString
End Try

End Sub

Visual Basic .Net Coding Samples

By hagrin - Posted on 09 February 2007

Below are code samples utilizing Visual Basic .Net. If you have any questions, comments or corrections on any code sample, please email me at hagrin at gmail dot com and I'll try and get back to all user inquiries as soon as possible. Thank you and hopefully this code will proove to be helpful.

Disable a Domain Account in Active Directory
Unlock a Domain Account in Active Directory

C#.Net - How to Unlock a Domain Account in Active Directory

By hagrin - Posted on 09 February 2007

How to Unlock a Domain Account in Active Directory utilizing C# .Net - (note: you must have Domain Admin privledges to execute this code successfully and you must import the System.DirectoryServices namespace):

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.DirectoryServices;

...

private void btnDisableUser_Click(object sender, System.EventArgs e)
{
string strUserName = "InsertUserNameHere";
DirectoryEntry usr = new DirectoryEntry("LDAP://dc=InsertDomainHere, dc=COM");
DirectorySearcher searcher = new DirectorySearcher(usr);
searcher.Filter = "(SAMAccountName=" + strUserName + ")";
searcher.CacheResults = false;
SearchResult result = searcher.FindOne();
usr = result.GetDirectoryEntry();
usr.Properties["LockOutTime"].Value = 0x0000;
usr.CommitChanges();
}

C#.Net - How to Disable a Domain Account in Active Directory

By hagrin - Posted on 09 February 2007

How to Disable a Domain Account in Active Directory utilizing C# .Net - (note: you must have Domain Admin privledges to execute this code successfully and you must import the System.DirectoryServices namespace):

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.DirectoryServices;

...

private void btnDisableUser_Click(object sender, System.EventArgs e)
{
string strUserName = "InsertUserNameHere";
DirectoryEntry usr = new DirectoryEntry("LDAP://dc=InsertDomainHere, dc=COM");
DirectorySearcher searcher = new DirectorySearcher(usr);
searcher.Filter = "(SAMAccountName=" + strUserName + ")";
searcher.CacheResults = false;
SearchResult result = searcher.FindOne();
usr = result.GetDirectoryEntry();
usr.Properties["userAccountControl"].Value = 0x0002;
usr.CommitChanges();
}

SharePoint v3: Turn On Friendly Error Messages

By hagrin - Posted on 08 February 2007

Anyone who has worked with SharePoint extensively knows that when troubleshooting SharePoint errors you will be confornted with some of the most meaningless, generic error messages of any major application around. However, thanks to articles like this (which is where I first read this tip), SharePoint developers and administrators can turn on more descriptive, "friendly" error messages by making two changes to your web applications web.config file -

  1. Set customErrors=off
  2. Set CallStack="true"

Making these two changes in your development environment will really help your SharePoint developers and admins troubleshoot technical issues.