Welcome to weblogs.com.pk Sign in | Join | Help

Adeel bin Khalid

"When a Man's Education is Finished; He is finished"
WCF and NHibernate: DateTime Null Problem

While sending Nullable DateTime data type you might get an exception: "Cannot convert int32 to datetime" or something like this. This is because WCF doesnt go well with nullable datetime.

 

Solution:
Add new methods in the class that uses nullable datatype. Add [OnSerializing] and OnDeserializing] Attributes and their respective methods in your class. In OnSerializing method assigh min datetime to your nullable field. And OnDeserializing method, assign the null value to the datetime field that has min date.


Class testing
{
  public DateTime myNullableDate? = null;
 
    [OnSerializing]
    internal void OnSerializingMethod(StreamingContext context)
    {
        if(myNullableDate==null)
                 myNullableDate = mindate;//change the mindate with right method call
    }

    [OnDeserializing]
    internal void OnDeserializingMethod(StreamingContext context)
    {
         if(myNullableDate== mindate)
                myNullableDate = null;
    }

}

CSS Overriding

Finally I have overridden my blogs CSS. Checkout the title pic :) nice isnt it :)

just placed the following code in "CSS Overrides" section of the blog and see the magic

#masthead
{
 background: #ffffff;
 background-image: url(http://weblogs.com.pk/photos/abk/images/158985/original.aspx);
}

Hosting WCF with Windows Process Activation Service

My Environment:
Windows Server 2008
IIS 7

While hosting my WCF service, which uses net.tcp bindings, on Process Activation service I experienced the following error:

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

Solution:

1) Go to the command prompt with administrative rights
2) Run the command : %windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\servicemodelreg -i

This will install the required support for WCF.

ASP.NET MVC 1.0 Released
ASP.NET MVC 1.0 is released. See the detail on Phil Haack blogs. A video is also available on channel 9 explaining the MVC Pattern. You can also checkout more videos on the official website
For SharePoint Developers

Below are some awesome references available on Heather Solomon blogs

SharePoint 2007 Design Articles and Info  

This one rocks... 

CSS Reference Chart for SharePoint 2007 

Visual Studio 2010 Tools for SharePoint Announced

Paul Andrew posts some of the new capabilities of VS2010 for SharePoint developers.

Web Q&A (ASP.NET Session State, Validation, DataGrids, and More)

See the web Q&A published in MSDN Magazine in November 2005.

http://msdn.microsoft.com/en-us/magazine/cc163708.aspx

These questions are good for both the interviewer and interviewee :)..

MOSS: The form cannot be displayed because session state is not available.

I have seen two solution of the "The form cannot be displayed because session state is not available." error while loading an InfoPath form in XMLFormView Control. One is a change in web.config file. Lot of people do not recommend this change. The second solution is doing something with the SharedServices. 

However, this error could also occur if EnableSessionState="True" is absent in the page directive of your asp.net page. Your page directive should look something like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyCustomPage.aspx.cs" Inherits="CustomPage_MyCustomPage" EnableSessionState="True" %>

 problem solved Smile

MOSS: XmlFormView Control

Here is a nice article about using an XmlFormView Control  

A browser-enabled InfoPath form template is functionally equivalent to a form designed to run in Microsoft Office InfoPath 2007, but when it is published to and opened from a server running InfoPath Forms Services, it does not require Office InfoPath 2007 to be installed on the computer that uses the form. InfoPath Forms Services, as part of either Microsoft Office Forms Server 2007 or Microsoft Office SharePoint Server 2007, includes the XmlFormView ASP.NET control, which you can use to render a browser-enabled form in a custom Web page. The XmlFormView control benefits enterprises that want to incorporate the functionality of InfoPath forms into their organizational Web infrastructure.

MSDN Article: Hosting the InfoPath 2007 Form Editing Environment in a Custom Web Form

MOSS: Document Imaging and Capturing Solution

If you are looking for a document capturing solution with SharePoint, check KnowledgeLake. Normally following are the phases involved in bulk document capturing:
1) Batch Preparation [Human Process]
2) Scanning [Human + Computer Process]
3) Metadata Entry [Human + Computer Process]
4) Metadata Verification [Human + Computer Process]
5) Putting the documents back as they were before batch preparation [Human Process]

These phases are mostly done in a distributed environment. Where set of people handle only one activity, just like a factory environment. The solution must have the capability of handling distributed processes.

MOSS: Working with SPFieldUrlValue

See the code below, how easy it is to set the URL field value :)

SPListItem myListItem = 'write the code to get the list item having a Link item attribute'
SPFieldUrlValue myLink = new SPFieldUrlValue();
myLink.Description = "Adeel's Blog"
myLink.Url = "http://www.weblogs.com.pk/abk"
myListItem["Name of the Link Attribute"] = myLink;
myListItem.Update();

MOSS: Programmatically Launch/Initiate a Workflow

Following code launches/initiates a workflow. Well I think I dont have to write "Programmatically Lunches" it cz its a code snippet so i guess its understood....  :)

//GUID of the wokflow... you can get this from your workflow.xml file

const string WF_GUID_STRING = "2086550f-f098-41b8-9b0d-3e06125278a4";

 

SPWorkflowManager wfManager = application.Web.Site.WorkflowManager;

 

//Get the Association Template of your workflow.

SPWorkflowAssociation associationTemplate = myDocLib.WorkflowAssociations.GetAssociationByBaseID(new Guid(WF_GUID_STRING));

 

//start it.....

wfManager.StartWorkflow(myDocLib.GetItemByUniqueId(application.UniqueId), associationTemplate, string.Empty);

 

It can be done in an item event receiver or in your custom code.

MOSS: Add Folder Type "Custom Content" Item in a List

Following code snippet adds a Folder type "Custom Content Type" in a Document Library

SPListItem myFolder = myDocLib.Items.Add(myDocLib.RootFolder.ServerRelativeUrl.ToString(),
                                                                       SPFileSystemObjectType.Folder, "New Folder");

 

SPContentType itemtype = myDocLib.ContentTypes["Name of Custom Content Type"];

 

myFolder.Update();

thats it..... :)

How to debug Event Receiver in SharePoint

I have also worked on IBM FileNet Content Engine’s Events so I used the same technique in MOSS to debug EventReceiver. Yes the same old “Writing in Text File” trick..

public override void ItemAdded(SPItemEventProperties properties)
        {
            try
            {
                if (properties.ListItem.ContentType.Name != "Folder")
                {                   
                   //your code goes here

                   //You can also call writeError method here to work as watch
   
                }
            }
            catch (Exception ex)
            {
                writeErrors("Error: " + ex.Message);
            }
        }


        private void writeErrors(string message)
        {
            TextWriter tw = new StreamWriter(@"c:\error.txt",true);
            tw.WriteLine(message);
            tw.Close();
        }

State Machine or Sequential Workflows; The decision parameter
I was reading some posts on MOSS workflows and came across a post which gave me a clear decision parameter. As I am new to Windows Workflow Foundation so I was unable to decide which type of workflow should be used for a certain problem. And now I am sure which way to go when it comes to choosing one..
 
If the workflow has a defined path, A, B, C and D. And the workflow will always move from A to B, B to C and C to D then sequential type is the one. If this order can be changed depending upon the user response then it's a State Machine workflow. For instance, there is a change where the process moves from A to C, then C to B, then B to A and so on. Here the path is selected on the basis of user response. The nice thing, which I personally like, about state machine is that you can create a sequential workflow within the state machine. So use your imaginations and develop some workflows....
More Posts Next page »