Windows Phone 7 development !

I have started learning WP7 application development as I have experience in Silverlight development. This is the first time I’m learning about Mobile applications development. To be honest it is really interesting to learn about mobile application platform. But, I’m little bit worried about WP7 application development as it is yet to reach the market as that of iPhone and Android.

The History of Microsoft’s mobile OS releases also raises questions. But I read everywhere that Microsoft is in the right direction this time with WP7 which supports Silverlight and XNA. I have been following few blogs that has really nice articles on WP7 development.

1. 31 Days with WP7 – A Collection of Windows Phone 7 (Mango) Tutorials You Must Read
2. http://sudheerkovalam.wordpress.com/
3. http://blogs.microsoft.co.il/blogs/alex_golesh/archive/tags/Windows+Phone+7/default.aspx
4. http://www.silverlightshow.net/items/Windows-Phone-7-Part-1-Getting-Started.aspx
5. http://blogs.msdn.com/b/wriju/archive/tags/windows+phone+7/
6. 31 Days of Windows Phone
7. WP7 Stock Quoting Demo Series
8. Windows Phone 7 Geek articles/
9. Microsoft Feed WP7 articles
10. 30+ Excellent Windows Phone 7 Development Tutorials
11. Rudi Grobler
12. igrali/
13. debug mode……
14. http://www.diaryofaninja.com/tag/windows-phone-7

Hope they are useful to anyone who wants get in to Windows Phone 7 development.

SharePoint Caveats – 1: Redirecting in Item Deleting event receiver.

I have been working in SharePoint for the past 2 years. I have encountered numerous bugs in SharePoint which makes me bewildered about Microsoft’s carelessness. So, I have decided to write a series of blog posts about the bugs in SharePoint (2010).

This is my first post in the series. In this I’m going to describe the bug that I found in the Item Deleting event receiver in SharePoint compared to the Item Adding event receiver.

In SharePoint event receivers we have options to cancel an event from occurring. We can also redirect to an application page or a web part page after canceling the event from occurring.

Here is the code for Canceling an Item Adding event from occurring and redirecting to an Application page .

           properties.Cancel = true;
           properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
           properties.RedirectUrl = "/_layouts/DeletingEventReceiver/ErrorPage.aspx";
           this.EventFiringEnabled = false;

Let us see what is the bug in SharePoint event receiver with respect to the above coding.

1. Create an Event receiver project with Item adding and Item deleting event receivers targeting Document Library template..

2. Now, add an Application Page to your project.

3. In the Item Adding event receiver add the above code as shown below.

public override void ItemAdding(SPItemEventProperties properties)
       {
           base.ItemAdding(properties);

           properties.Cancel = true;
           properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
           properties.RedirectUrl = "/_layouts/DeletingEventReceiver/ErrorPage.aspx";
           this.EventFiringEnabled = false;
       }

4. Deploy the solution in to SharePoint. Go to any of the document libraries in your SharePoint site, add a document and you will see that you are being redirected to an application page as shown below.

Untitled

5. Now, comment the code in the Item Adding event receiver and copy & paste the same code in to the Item Deleting event receiver as shown below.

public override void ItemDeleting(SPItemEventProperties properties)
       {
           base.ItemDeleting(properties);

           properties.Cancel = true;
           properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
           properties.RedirectUrl = "/_layouts/DeletingEventReceiver/ErrorPage.aspx";
           this.EventFiringEnabled = false;
       }

Deploy the solution.

6. Now, go to any of the document libraries and try to delete a document by clicking the delete option in the context menu of the document or from the ribbon menu.

7. You will see that you are not being redirected to the application page (as shown below) as in Item Adding event receiver.Untitled

As you see above you are taken to the default SharePoint error page instead of the application page that we created.

Alright, fine do not panic we still have our code that we implemented above in the Item deleting event receiver functioning somewhere inside SharePoint.

I will show where.

In the context menu of the document click View Properties, you will see a pop up with the properties of the document. In the ribbon menu of the pop up click Delete Item as shown below.

Untitled

And now you will be taken to the custom Application page that we had created as below.
Untitled

Fine, we have successfully finished discussing about a SharePoint bug. Thanks

Update: This blog post was discussed  here in the SharePoint forum. As you can see there, an explanation was given by a Microsoft guy saying “While deleting an item, the HTTPContext may be null. In this case, the URL redirection might fail, and we treat CancelWithRedirctUrl as CancelWithError to show the error message to the user.“, that being said, will try to come with a solution.

To check if a List Item in a SharePoint list has been approved from all the workflows attached to it

Well, in this blog post we are going to see how to check if an SPListItem has any workflows are associated to it and are not approved. I’am not sure if there are any blogs available to do this since I did this on my own 😀 .

I did this using the Workflow object model. Let us start looking at the coding.

1. First, we need to get the workflows that are associated with the list using the WorkflowAssociations class and store it in a SPWorkflowAssociationCollection object as below.

SPWorkflowAssociationCollection wfAssColl = olist.WorkflowAssociations;

2. Now, let’s loop through each workflow in the wfAssColl (after checking if the count is not 0) to get the Field that represents the workflow and also the static name of the field.

             if (wfAssColl.Count!= 0)
                   {
                       foreach (SPWorkflowAssociation wflow in wfAssColl)
                       {
                           SPFieldWorkflowStatus fld = (SPFieldWorkflowStatus)ilist.Fields.GetField(wflow.Name);

3. Get the SPListItem’s value in the corresponding workflow field that was retrieved above. Check if the value is equal to “16”.

                         if (Convert.ToString(oitem[fld.StaticName]) != "16")
                          return false;
                        }
                     }

4. If the value is not equal to 16 then the workflow for the item is not yet approved and returns false.

Here is the complete code:

SPWorkflowAssociationCollection wfAssColl = olist.WorkflowAssociations;
 if (wfAssColl.Count!= 0)
                   {
                       foreach (SPWorkflowAssociation wflow in wfAssColl)
                       {
                           SPFieldWorkflowStatus fld = (SPFieldWorkflowStatus)ilist.Fields.GetField(wflow.Name);
                          if (Convert.ToString(oitem[fld.StaticName]) != "16")
                            return false;
                        }
                     }

Hope this is helpful for anyone if at all anyone is in need of such a solution. Thank you.