There are plenty of guides out there detailing how to create a new Windows SharePoint Services v3 web part, so I won't write another one here. Those walkthroughs are great, but sometimes I just want a quick outline of the steps needed to get things done. So while creating my own web part, I kept track of the steps and created my own simple outline. Here it for your use:

  1. Create the Web Part
    1. Create the DLL project in VS2005.
    2. Add Reference to System.Web.dll.
    3. Create a new Class file, inherit from System.Web.UI.WebControl.WebParts.
    4. Override the Render method and use writer to output the content of the web part.
    5. Strong name the assembly if installing to GAC.
    6. Compile.
  2. Deploy Web Part (updated 11/2/06 with B2TR)
    1. For strong named assemblies, follow these steps:
      1. Copy your assemblies to the C:\Inetpub\wwwroot\wss\VirtualDirectories\[site directory guid]\bin folder or install to the GAC. Note assemblies in the \bin folder have less priviledges than those in the GAC. Test your web part to make sure there aren't any security problems.
      2. Modify the site's web.config and add a <SafeControl> entry. Should look something like:
        <SafeControl Assembly="[Web_Part_Assembly_Name], Version=[Version_Number], Culture=neutral, PublicKeyToken=[Public_Key]" Namespace="[Namespace]" TypeName="[Class_Name]" Safe="True" />
    2. For non-strong named assemblies, follow these steps: 
      1. Copy your assemblies to C:\Inetpub\wwwroot\wss\VirtualDirectories\[site directory guid]\bin folder.
      2. Modify the site's web.config and add a <SafeControl> entry. Should look something like:
        <SafeControl Assembly="[Web_Part_Assembly_Name]" Namespace="[Namespace]" TypeName="[Class_Name]" Safe="True" />
  3. Configure the Web Part in SharePoint
    1. Go to Site Settings, Galleries, Web Parts, click New.
    2. Select your web part and click Populate Gallery button. Make sure the web part now shows up in the web parts gallery. If the web part doesn't show up in the list of New Web Parts, may need to iisreset.
  4. Edit a page and add your web part in from the Gallery.

Note that these steps are for WSS v3 Beta 2. These steps may change at RTM. I'll try to keep this up to date if things change.

For more detailed walkthroughs of how to create ASP.NET 2.0 style web parts for WSS v3, here are some resources/links:

with 5 Comments

While I was testing out more of VS.NET 2005's features, I noticed this:

Finally there's word wrapping in the Output Window! Now with wrapping:

... but everyone's code is perfect right? No one ever has any build errors?

 

 

with 0 Comments

Ever wanted to create a batch file, but wished you could write the code in C#/.NET? Have you ever wanted to try out a snippet of code, but didn't want to go through the trouble of creating a new solution, then a command prompt project in Visual Studio?

I asked these exact same questions when I started searching for a way to write .NET batch files. Those of you who have heard of Longhorn probably have heard about Monad. This is Longhorn's new command shell that allows you to pipe and return data similar to unix shells. The cool thing about Monad however is that it allows you to write little managed code snippets called commandlets. This means you can write mini batch files that are in .NET code and can pass and return .NET objects. 

Monad is great, but how about now? Well it turns out that someone has written a really neat batch file template that allows you to write the batch file as a standard .NET command line project. By running the batch file, it dynamically compiles your code into a command line application and then runs it passing in any command line arguments you pass in. The original blog post about this is here:

http://wintellect.com/WEBLOGS/wintellect/archive/2005/03/23/931.aspx

and here's an example of what I created so I can hash some passwords for testing:

@echo off & goto :beginScript
#endif
#line 4

/******** Put compilable C# code after this line ********/
using System;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;

class App {

 public static void Main(String[] args) {
  if (args.Length < 2) {
   DisplayUsage();
   return;
  }
  
  string salt = args[0];
  string password = args[1];
  
  string hashPassword = App.HashPassword(salt, password);
  
  Console.WriteLine ("Your hashed password is: " + hashPassword);
 }
 
 private static string HashPassword (string salt, string password) {
  string inputText = string.Format("{0}{1}", password, salt);

  Byte[] clearBytes = new UnicodeEncoding().GetBytes(inputText);
  Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
  
  return BitConverter.ToString(hashedBytes);
 }
 
 private static void DisplayUsage() {
  Console.WriteLine ("Hashes the input password as used...");
  Console.WriteLine ();
  Console.WriteLine (" HASHPASS.BAT ");
  Console.WriteLine ();
  Console.WriteLine ("         The salt to add to the hash.");
  Console.WriteLine ("     The password to hash.");
  Console.WriteLine ();
 }
  
}
 

/*******************************************************/

#if NO

:beginScript
setlocal
set versions=
:: Uncomment the following line (remove REM) to limit the fx versions. Uses newest by default.
rem SET versions=v1.0.3705 v1.1.4322
set tempCs=%~s0
set tempCs=%tempCs:\=.%
set tempCs=%tempCs::=.%
set tempCs=%TEMP%\%tempCs%

if not exist %tempCs%.exe goto :build
::check for up-to-date .exe
copy %~s0 %tempCs%.tst 1>nul 2>&1
for /F %%i in ('dir /od /b %tempCs%.*') do set latestCs=%%~xi
del %tempCs%.tst 1>nul 2>&1
if "%latestCs%"==".exe" goto :run

:build
if defined versions FOR %%c IN (%versions%) DO IF EXIST %SystemRoot%\Microsoft.Net\Framework\%%c\csc.exe (SET netpath=%SystemRoot%\Microsoft.Net\Framework\%%c)
if not defined versions for /F %%c in ('dir /b /on %SystemRoot%\Microsoft.Net\Framework\v?.*') do if exist %SystemRoot%\Microsoft.Net\Framework\%%c\csc.exe (SET netpath=%SystemRoot%\Microsoft.Net\Framework\%%c)
if not exist %netpath%\csc.exe GOTO noFramework
echo #line 1 "%0" >%tempCs%.cs
echo #if NO >>%tempCs%.cs
TYPE %~s0 >>%tempCs%.cs
%netpath%\csc.exe /out:"%tempCs%.exe" %tempCs%.cs >nul
if ERRORLEVEL 1 goto badCompile
if exist %tempCs%.cs DEL /q %tempCs%.cs

:run
%tempCs%.exe %*
goto :EOF

:badCompile
%netpath%\csc.exe /out:"%tempCs%.exe" %tempCs%.cs
IF EXIST %tempCs%.cs DEL /q %tempCs%.cs
goto :EOF

:noFramework
ECHO ERROR: This batch file requires the .Net framework.
goto :EOF

#endif

 

Web services is all about interoperability right? Of course but does it always happen? No. You might think the reason is because platforms do not adhere to the spec. This may be true, but not always. Sometimes it's the platform specific implementations that ruin interoperability between different platforms. (source)

Consider, for example, what a Vector in Java would translate to. Let's say you want to implement a .NET application to consume the Web service. Is there such a thing as a Vector in .NET? Perhaps it can be said that a Vector in Java is the same as an ArrayList in .NET, but can you guarantee that the mapping between Java and .NET is always Vector <-> ArrayList?

This new article posted up on MSDN discusses some of these issues and provides some tips on creating Web services that are created WSDL-first rather than implementation first.

http://msdn.microsoft.com/vstudio/java/interop/websphereinterop/default.aspx

 

with 0 Comments

In .NET, we typically use DateTime.MinValue to indicate a NULL or undefined date time value. This works fine if you are only working with .NET code, however if you try to save this into a SQL database, then things will not work.

The reason is because the DateTime type in SQL does not have the same range as the DateTime in .NET. The DateTime type in .NET can accept date time values in the range between 0:00 1/1/0001 (the value of MinValue) to 23:59 12/31/9999 (the value of MaxValue). On the other hand, the DateTime type in SQL can accept date time values in the range between 1/1/1753 to 12/31/9999. So there is a gap from 1/1/0001 to 1/1/1753.

Therefore, this is why you will get a SqlDateTime overflow error message if you try to save a .NET DateTime.MinValue into a SQL DateTime variable. DateTime values are also tricky when working with interoperability (ie. calling Java Web services). Just an additional item to keep in mind when writing code.

 

with 6 Comments

Here are some of my favorite tools I use for development besides VS:


Emeditor Notepad replacement.
FxCop Test for best practices.
NUnit Unit testing .NET code.
Subversion Local source control (similar to CVS).
NDoc API documentation generator.
Reflector .NET Inspect .NET assemblies and decompile .NET IL code.
tcpTrace Proxy to capture TCP traffic.

What do you use?

with 5 Comments