Dailycode.info

Short solution for short problems

Spam poison

I use this on every page that holds email adresses. This keeps the bugs out!

This is what is does:

Robots who collect e-mail adresses will end up in an endless loop. They will keep on getting dynamically created email adresses, creating spam in their own databse. The brain's behind the spambots will have to clean up their data and start over again. This is not a guarantee that spam bots will not find your email!


Checked listbox: CheckItems / SelectedItems

I was working with a checked listbox and had a simple thing to do:

Save all the selected items to a string (Items are seperated by a space) in the databse. First I thought, no problem, just iterate through the list items, check if the item is selected and add it to the string.

But then I found the selecteditems property. At first I couldn’t cast it to an array, so after a little surfing I came up with this solution. I quickly found that I had to use the CheckedItems property. Because SelectedItems only gets the items that are highlighted, CheckedItems gets the items that are checked. Here the code:

string[] destination = new string[cbxlstRooms.CheckedItems.Count];
cbxlstRooms.CheckedItems.CopyTo(destination, 0);
string rooms=string.Join(" ",destination);
_study.CurrentStudy.Rooms = rooms; //this is where I set the object that is saved to the DB later.
 

And this works fine!

Here's an example of a checked list box I used:

checked listbox


Daily WSS: Web services

Web services

WSS 3.0 exposes the whole functionality of the site through web services making it very easy for 3rd party application to connect to the platform. You can manage documents, list, etc, via these web services. This can come is very useful to publish automatic generated reports. You can use the SharePoint search query to find certain documents or list items. The web services are better explained in the Microsoft SDK: http://msdn2.microsoft.com/en-us/library/ms441339.aspx Here an overview of the available web services with a short description.

Microsoft Windows SharePoint Services Web services provide methods that you can use to work remotely with a deployment of Windows SharePoint Services. The following table lists and describes the available Web services.

Service

Description

Administration

Provides methods for managing a deployment of Windows SharePoint Services, such as for creating or deleting sites.

Alerts

Provides methods for working with alerts for list items in a SharePoint site

websvcAuthentication

Provides classes for logging on to a SharePoint site that is using forms-based authentication.

Copy

Provides methods for copying items between locations in Windows SharePoint Services.

Document Workspace

Provides methods for managing Document Workspace sites and the data they contain.

Forms

Provides methods for returning forms used in the user interface when working with the contents of a list.

Imaging

Provides methods that enable you to create and manage picture libraries.

List Data Retrieval

Provides a method for performing queries against lists in Windows SharePoint Services.

Lists

Provides methods for working with lists and list data.

Meetings

Provides methods that enable you to create and manage Meeting Workspace sites.

People

Provides methods for working with security groups.

Permissions

Provides methods for working with the permissions for a site or list.

SharePoint Directory Management Service

Provides methods for remotely managing distribution groups.

Site Data

Provides methods that return metadata or list data from sites or lists in Windows SharePoint Services.

Sites

Provides a method for returning information about the site templates for a site collection.

Search

Provides methods for remotely performing searches within a Windows SharePoint Services deployment.

Users and Groups

Provides methods for working with users, site groups, and cross-site groups.

Versions

Provides methods for working with file versions.

Views

Provides methods for working with views of lists.

Web Part Pages

Provides methods to send and retrieve Web Part information to and from Web services.

Webs

Provides methods for working with sites and subsites.


Daily WSS: Sites

Sites 

An administrator or a user with sufficient rights has the possibility to create new sub-sites. He can choose a template and colour theme provided by the organization. You can create for example sub sites for each project. These sites are created from a template and contain automatically the correct layout and content. The sites can have different security then their mother site or children.
There is a possibility to save the site as template, with or without content.
It is possible to create these sites with web services, hence an external application can create these sites. From your site, you could create a new sub site when a new project is launched. Each site has a search functionality that can search the complete content of the site, including the content of the documents. Site content is created with web parts. You can have different web parts, HTML content, pictures list, document library web part (a view on the content of the library), custom web parts, etc.


Daily WSS: Content types

Content Types

Content types are types created by your organization. They can describe a document type or list item. A content type has its own workflow and specific metadata. These types can be reused throughout the entire site and are managed at site level.

For example: a financial form, it has a workflow that sends an email to the financial assistant, and has extra fields like department, total cost … When somebody creates a document of this type; it inherits these properties and activates the workflow.
You can still add extra metadata or specific workflows on items.


Daily WSS: Lists

Lists 

Lists in SharePoint can contain almost all types of data. You can add multiple attachments to list items; you can add metadata and calculated fields to the list. Metadata can be one of the following types: Single line of text, multiple lines of text, choice, number, currency, date and time, lookup (values in a list or library on the site), yes/no, person or group, hyperlink or picture, calculated (you can perform many functions on fields and show the result in this column).
It is possible to add different content types to the list, multiple workflows and in dept security… A list can be a very powerful source of information.
You can look at a list like a database table with a web interface and much more functionality. You can create these lists through a web interface and manage them. You can add columns at any time to the list, change views and order. The content is also completely searchable.
It’s possible to receive list content or notifications on your mobile.


Daily WSS: Document libraries

Document libraries

These libraries are specially created to store documents in a central place and provide lots of default functionality on these documents.
You can upload or create new documents to a library using the web interface or your windows explorer. That’s right; SharePoint enables you to control documents from your windows explorer, office application or the World Wide Web. You can even add documents to your library by email! There is a possibility to work with different content types in the same library, content types and their strength is explained later on this blog.

You can secure documents, folders and libraries on a different level. You can add workflows to libraries or content types.
WSS 3.0 offers publishing on documents. You can use version history with major and minor versions. The history of documents is kept by the system if we enable versions; therefore it is really easy to rollback previous versions. When multiple users are working on the same documents you can use the check in, check out functionality.

You can create and edit documents using your appropriate office application. When you open the document, the system will choose the correct office application and lets you chose whether to check out or not. You can even change the metadata of the document within the office application of you are using Office 2007.
Content of the documents is crawled by the system. This enables you to perform a search based on the contents of the documents.
It’s possible to receive content or notifications on your mobile.


Google AdSense

As you can see on the right section of this site, I'm being sponsored by Google AdSense. This will not make me rich, in fact it's only for testing purpouse. But if you're site is a popular site or is going to be, it is a very good idea to use this functionality. It is really easy to use, and the only requirement is that you have a gmail account. There are 3 main possibilities of add's:

  1. 1 Content add's : adds that are shown are based upon the content of your site, you can use banners horizontally of vertically.
  2. 2 Search add's: a search box that saerches your site and adds add's to the search results
  3. 3 Pointers: to send users to specific products or services.

 

You can start using AdSense here!

Feel free to click on the add's on this site and make some money, I recently clicked on one add and got some valuable information, so don't think it's all spam or rip off, it are good products that has to sell themselves!


Wait cursor for Windows forms

I think that every good developer has to be aware not to invent the wheel again and again. I found a great opensource project that helps window forms applications build in a wait cursor every time the system is doing some work.

You will need to reference the dll in your project and put these 2 lines somewhere in the startup of your application:

ApplicationWaitCursor.Cursor = Cursors.WaitCursor;


That’s it!

ApplicationWaitCursor.Delay = new TimeSpan(0, 0, 0, 1, 0);  // Delay of 1 second
ApplicationWaitCursor.Delay = new TimeSpan(0, 0, 0, 0, 250);  // Delay of 250 mili seconds
 
 

You can find a demo project and the source code here: http://www.codeproject.com/cs/miscctrl/WaitCursor.asp

I used it myself and must admit that this code works really fine. You can see that the developer has put some effort in it! 

I only notice one small problem during testing. When I clicked on a scroll bar in a listbox, and hold the mouse button down for a while to scroll, the wait cursor appeared.

You can filter events, below I adapted the ApplicationWaitCursor.cs and added the WM_LBUTTONDOWN message. I declared the varible : private const int WM_LBUTTONDOWN = 0x0201; on top and added this code:||
m.Msg == WM_LBUTTONDOWN to the if in the MessageFilter.PreFilterMessage method. Now when I left click on the mouse and keep it down, the wait cursor is not shown. But now every time whe do a left mouse click, the wait cursor will not be shown. So I decided to leave it this way and set the delay at 500 ms. Apart from this small problem, the application is now much user friendly because every time the system is doing some work, the wait cursor informs this to the user.

Here are some pre filtered messages I pickup up from comments on the post:

bool IMessageFilter.PreFilterMessage(ref Message m)
{
if (
m.Msg == WM_NCLBUTTONDOWN || 
m.Msg == WM_LBUTTONDOWN || 
m.Msg == WM_RBUTTONUP || 
m.Msg == WM_CONTEXTMENU ||
m.Msg == WM_SYSKEYUP ||
m.Msg == WM_SYSKEYDOWN)
_cursor.Enabled = false;
...Message defitions are:
private const int WM_LBUTTONDOWN = 0x0201;
private const int WM_RBUTTONUP = 0x0205;
private const int WM_CONTEXTMENU = 0x007B;
private const int WM_SYSKEYUP = 0x0105;
private const int WM_SYSKEYDOWN = 0x0104
 
The list of all mouse events: http://msdn2.microsoft.com/en-us/library/ms674824.aspx
 

 


Google fan

As a huge Google fan, I try to be updated about the latest new features Google presents.

An agenda with free sms notification makes my life a lot more easy. You know when use try to use an agenda, but still you forget to look in it at the most important times. You forget sometimes an appointment with the dentist. Not anymore. Google offers free sms notification.

Also Picasa has a lot to offer. You can store 2 Gig photo's on the web, if you make the quality web-based you can put you're whole life in there. You can map your photo's, so you can see with a google map where the picture was taken. You can also use an embedded flash tool to show your pictures everywhere:

And don't get me started on iGoogle or google analytics, whow, this is really crazy.

Google also lets you keep your web history. A few days ago I was looking in my mail for a aknowledgement about something I ordered, but I could't find it. I forgot which url. I was a little desperate, because I paid with credit card, but didn't recieved a mail to track the order. I ended up in my google web history and after a while I founded the search text I used to find the website. And I got my order back.