Sunday, March 13, 2011

Visual Studio Debugging - Attach to Process

Debugging!!!

I am sure this is the every good programmers way of finding and fixing bugs. Now I am going to give you all a brief idea about this nice feature called Attach to Process in Visual Studio. You can find this under Debug menu in Visual Studio. We can use Attach to Process to break into a running application and begin a debug session. This feature can be used mainly for debugging web applications which can be a  running instance of a web application or a web service hosted by IIS. ASP.NET applications will run in either an aspnet_wp.exe process (for IIS 5.x), or a w3wp.exe process (for IIS 6.0 and after).

Now when we click the Attch to Process it will display the following window.

Attach To Process
In here it shows all the available processses. There are several options you can select. If the program that you want to debug is running on another computer, you must first select the remote computer by selecting the Qualifier.

In the Attach to box, make sure that the type of code you will debug is listed. The default Automatic setting tries to determine what type of code you want to debug. If the automatic setting is not appropriate click Select and Select the code type and click Ok. In here I am selecting Managed (v4.0) code, Native code and T-SQL code. Actually when we click on the process, you can see the code type changes according to the selected process.

Select Attach to
Managed (v4.0) code, Native code, T-SQL code


We can select either to show processes from current user or show processes from all users by clicking the tick on Show processes from all users.

And the next option is bit important and that is Show processes in all sessions. Sometimes when you click the Attach to Process you might not see a single w3wp.exe running. The reason behind this can be one of the following.
  • The web application/web service might not be running.
  • Show processes in all sessions might not be ticked.
So if your web application/web service is already running and still you can't see the w3wp.exe under Available Processes you should tick the Show processes in all sessions and now you will be able to see running w3wp.exe process. You can always click Refresh to get tge current list of processes.

Now open the .cs file you want to debug using Visual Studio and set a break point to where you want to start debugging. Then go to Attach To Process and select the w3wp.exe and in your web application/web service go to the page where you have set the break point. Now when you enter to the break point, you can start debugging.

Things to Note:

You might wonder how to identify Which w3wp.exe PID corresponds to which application pool ?

     1.   In IIS 6 (Windows 2003):

The easy way to solve this problem was to call a Visual Basic script file that was located in the C:\Windows\system32\ folder. The file was called iisapp.vbs, and the output of this command listed the instances of w3wp.exe present on the system, their PIDs and to which application pool they belonged to.

     2.   In IIS 7 (Windows 2008) and IIS 7.5 (Windows 2008 R2)

The Visual Basic script file has been removed. Most of the IIS 6 script files that were dedicated to a single task (like iisapp.vbs) have been integrated into a command line utility that can be used to administer the IIS server as a whole. This utility is called appcmd.exe and it is located in the C:\Windows\system32\intesrv\ folder.

CAUTION: to access the tool you must launch the command line prompt with administrator rights, otherwise it will not work. To do this simply right click on a command line short cut and chose 'Run as Administrator' from the context menu.

Then navigate to the folder where appcmd is located (C:\Windows\system32\intesrv\) and run the following command: 
appcmd list wp –
This will list all the instances of the w3wp.exe process (worker process) that are present on your server with their respective PIDs and application pools.

For example, lets say you have several w3wp.exes and one's PID is 6772. Type the following command.
appcmd list wp 6772
It will show what application pool it is belonged to.

You can always type iisreset from C:\Windows\system32\intesrv\ to reset and IIS and update the PIDs.

And that's a brief introduction about Visual Studio Attach to Process feature. Appreciate your feedback.

Happy Coding.

Regards,
Jaliya

Monday, March 7, 2011

Submitting data to a SharePoint 2010 List using InfoPath - CAML

After moving around with some heavy tasks in SharePoint I wanted to Submit data to a SharePoint list through a InfoPath web form which has a Submit button in it. Did some googling and saw a way of submitting data through SharePoint in built web services. Thought of trying it and started to work on it. But after some time trust me, what i felt was this way is not hard, neither so easy.

So I thought of giving you all a step by step guide to learn how to do this without much frustration.
For this task, you will need SharePoint 2010 and Microsoft Office InfoPath Designer 2010 installed in your machine. You will need to have good understanding about CAML(Collaborative Application Markup Language), knowledge of the methods of the SharePoint Lists web service and that would be all and you are ready to go.

First of all CAML is an XML based markup language used with the family of Microsoft SharePoint technologies. Unlike plain XML, CAML contains specific groups of tags to both define and display (render) data. To get more information visit,
http://en.wikipedia.org/wiki/Collaborative_Application_Markup_Language

To get more information about the SharePoint Lists web service, in your IE navigate to "http://servername/_vti_bin/lists.asmx?WSDL" and you will be able to see all the web methods associated with the Lists web service. For our purpose we will be using UpdateListItems web method.

Now let's start. I am assuming you as a beginner, so I am adding a lot of step by step screen shots to ease your work.

1. Create a Custom List in a SharePoint Site. I have named it as Employee. Now create some columns as per your need. Note that there will be a default column called 'Title' and lets not change it and keep it that way to store EmployeeName, I have created EmployeeAddress, EmployeeNo, EmployeeEmail as columns which are Single text. Note that when Column names does not contain any spaces and later I will describe the reason to put them in that way.

2. Open Microsoft Office InfoPath Designer 2010 and select a Blank Form and click Design Form. Then do as follows.

Form Options

Security and Trust

Full Trust

Programming

Design

Design

Design

Renaming the button


Add fields






3. In SharePoint site under Employee list, in ribbon under List Tools select List and then select List Settings. In that page click Advanced Settings and select Allow management of content types to Yes.

List Settings



4.  Again go to List Settings click Metadata navigation settings and copy the list GUID.

Copy list GUID

5. Go back to InfoPath form right click on listID and paste GUID under value field.




6. Open Notepad and type,

<?xml version="1.0" encoding="UTF-8" >?
<Batch>
<Method ID="1" Cmd="New">
     <Field Name='Title' />
     <Field Name="EmployeeAddress" />
     <Field Name="EmployeeNo" />
     <Field Name="EmployeeEmail" />
</Method>
</Batch>

Save the file as an xml file and name it Submit.xml.

7. Now lets create Data Connections. Go to InfoPath form and click Manage Data Connections. First we need to create a Receive Data connection. I am naming it as 'Submit'.


Receive Data

XML Document

Browse for the created Submit.xml file


Naming the connection as 'Submit'

8. Now we need to create a Submit Data Connection. Again in Manage Data Connections click Add.

Add

Submit Data

To a Web Service

http://servername/_vti_bin/lists.asmx?WSDL

UpdateListItems

listname

listID

Include : Text and child elements only

Updates

Secondary


Batch

Include : XML Subtree, including selected element


Web Service Submit


Edit Form Code

9. Click Edit Form Code and btnSubmit_Clicked event will be created. In that block, type the following code.

try
{
    XPathNavigator root = MainDataSource.CreateNavigator();

    // Retrieve the values for the separation list item
    string listID = root.SelectSingleNode("/my:myFields/my:listID", NamespaceManager).Value;
    string eNameDS = root.SelectSingleNode("/my:myFields/my:EmployeeName", NamespaceManager).Value;
    string eAddressDS = root.SelectSingleNode("/my:myFields/my:EmployeeAddress", NamespaceManager).Value;
    string eNoDS = root.SelectSingleNode("/my:myFields/my:EmployeeNo", NamespaceManager).Value;
    string eEmailDS = root.SelectSingleNode("/my:myFields/my:EmployeeEmail", NamespaceManager).Value;

    if (listID == null)
    {
    
    }
    else
    {
        //This is CAML xml file. it contains batch and method nodes
        XPathNavigator batch = DataSources["Submit"].CreateNavigator();

        batch.SelectSingleNode("/Batch/Method/Field[@Name='Title']", NamespaceManager).SetValue(eNameDS);
        batch.SelectSingleNode("/Batch/Method/Field[@Name='EmployeeAddress']", NamespaceManager).SetValue(eAddressDS);
        batch.SelectSingleNode("/Batch/Method/Field[@Name='EmployeeNo']", NamespaceManager).SetValue(eNoDS);
        batch.SelectSingleNode("/Batch/Method/Field[@Name='EmployeeEmail']", NamespaceManager).SetValue(eEmailDS);

        DataConnections["Web Service Submit"].Execute();
}
catch (Exception ex)
{
    ex.Message.ToString();
}

10. And finally thats all. Preview the form and try submitting the data. After that publish the form and upload the form template into SharePoint and start using.

There are few important things to remember carefully. 
  • There is a significant difference between Display name and the Field name. When we are doing the coding we are using the value under the Field name. If you can remember, I have mentioned to keep the default 'Title' column as it is, because if we rename the 'Title' column it will just change the display name. The Field name will be remain as 'Title'.
  • No of updating list fields should be the same as no xml field names.
  • When I am creating columns in SharePoint list, if you can remember I have included no spaces between words. Thats because it will add characters into Field names. So when we are referring to Field names from looking at Display names, the Field name is actually differs from the Display name.
  • List fieldname should be same as xml fieldname.
  • Make sure when creating the Submit Data connection 'Web Service Submit' to select following things,
    • listName - listID : Include : Text and Child elements only
    • updates - Batch : Include : XML subtree, including selected element

Appreciate your feedback. 

Happy Coding.

Regards,
Jaliya

Saturday, March 5, 2011

Programmatically Scanning APIs (TWAIN & WIA) for C#

I have been struggling for some time to develop a program to trigger a scanner. Now I am going to share some of the things I learned about programmatically scanning. There are variety of scanners and they use different kind of protocols to communicate with the computer. As many of the applications programs needed scanning feature in their applications, developers had to develop Application Programming Interfaces(API) for scanners. The API would be the interface that would be dealing with any kind of scanner. Simply means the application does not have to know how the hardware part in the scanner is working to access it directly. They just interacts with the scanner interface.

There are two main Standard Software Protocols or APIs that can be used to acquire images from a scanner.
  1. TWAIN
    • The word TWAIN is not an official acronym, however, it is widely known as "Technology Without An Interesting Name."
    • For more information visit, http://en.wikipedia.org/wiki/TWAIN
     2.   WIA (Windows Image Acquisition) (Sometimes also called as Windows Imaging Architecture)
    • Microsoft driver model and Application Programming Interface (API) for Microsoft Windows Me and later Windows operating systems that enables graphics software to communicate with imaging hardware such as scanners, digital cameras and Digital Video-equipment.
    • For more information visit, http://en.wikipedia.org/wiki/Windows_Image_Acquisition
In my next posts I will post, how these APIs has helped me to develop my program.

Happy Coding.

Regards,
Jaliya

Thursday, February 24, 2011

Basics Of MVVM in Silverlight

While I was doing a project using Silverlight, I had a requirement to cascade some combo boxes. As some might already know binding data to combo boxes in Silverlight is a real headache. So when I googling for some answers, I saw a lot of articles about a topic called data binding using MVVM. At first I had no idea what MVVM is and then I wanted to learn what MVVM is. After some reading I was amazed by the things that can be achieved with MVVM and I thought I might share some basics of MVVM with you all.

First of all MVVM(Model-View-ViewModel) is a great design pattern for Silverlight and Windows Presentation Foundation (which is commonly known as WPF). The MVVM has become a such overrated pattern is because it's powerful features. One of the best features of MVVM is it's close work with XAML based applications such as Silverlight.

To get a best idea about MVVM, I will explain the MVVM Triad (Model,View,View Model).
  • View is the user controls designed in XAML. Since I am mainly focuing on Silverlight, in Silverlight View is described in MainPage.xaml. 
  • The Model is used to access the data from a data source. 
  • The View Model is used the put all the logic behind the controls and to fill the gap between View and the Model. It actually bind or convert the information of Model to View information.
Using these three parts, MVVM provides powerful XAML binding for it's controls. If you are doing development with Silverlight or WPF I am sure some of you have already gone through the need of this nice pattern and if you have not gone through this pattern yet, very soon you will be going through. You can find more information and tutorials in the web on MVVM.

Happy Coding.

Regards,
Jaliya

Sunday, February 20, 2011

Error : Your mailbox appears to be unavailable. Try to access it again in 10 seconds - Microsoft Exchange 2010

Today for the first time in my life, I got the experience of installing Microsoft Exchange 2010 and that was really a nice one. My requirement was just simple, which was sending an Email from SharePoint to Exchange. I configured SharePoint to send Emails to my Exchange and when I checked from SharePoint my Emails were nicely sent.

But when I tried to log in to OWA (Outlook Web App) to check whether I have received my Emails, after typing the user name and password I got this nice error saying "Your mailbox appears to be unavailable. Try to access it again in 10 seconds". Since I am a beginner in Exchange I was confused and tried many things to fix it.

But after struggling for around 2 hours, at last I have managed to fix it now and I am so happy.

Solution was again, just a simple one. That is,
In services, Start the service "Microsoft Exchange Information Store". I think the problem was, without that service up and running Exchange can't map a mailbox to a user.

Now everything is fine and I have received my emails and I got the pleasure of confirming my Emails are successfully receiving from SharePoint.

Happy Coding.

Regards,
Jaliya

Monday, February 14, 2011

Silverlight UI Thread and Background Thread

One of the coolest features in Silverlight is UI threading. WPF is also provides UI threading. I got to know about this feature while I was trying to update the UI elements from my background thread. After googling around I saw a nice class that deals with threading which is the Dispatcher class. Mainly what Dispatcher class does is it provides services for managing the queue of work items for a thread.

One important thing that you should keep in your mind is that Silverlight recognizes the difference between UI threads and background threads. You just can't update controls designed in XAML through your background thread. You must invoke the UI thread by using the Dispatcher class.

We can simply do this by declaring a delegate to access the XAML DOM.

Dispatcher.BeginInvoke(delegate()
{
//update the UI
});


Happy Coding.

Regards,
Jaliya

Sunday, February 13, 2011

Geographic Information Systems(GIS) for SharePoint using Silverlight

These days Geographic Information Systems (GIS) are becoming more popular systems rather than ever before. Since currently I am working on developing a GIS, I thought I might share some things I got to know while developing.

First of all .net is a nice platform that supports developing GIS. Through SIlverlight, It seems to me that you can develop anything for your GIS. You can do all the customization per your need.

ArcGIS API for Microsoft Silverlight/WPF is one of the commonly used and one of the best free APIs that can be accessed within the Silverlight code. One of the greatest advantages of using Silverlight for your GIS is, you can attach your GIS into a SharePoint site very easily. Just add the Silverlight Application(.xap) to a document library of your SharePoint site, then add a Silverlight web part to a web page and configure the source for the Silverlight web part to the added .xap file and that's it. Your GIS will be nicely loading into your web page.

There is a mapping for SharePoint by ArcGIS for creating a GIS using SharePoint, but I don't think you will be able to do all the customizations you want by using it. Anyhow It's always good to explore that one too.

If anyone is developing or interested in Geographic Information System feels free to post your questions or comments here.

I am sharing some links for further reference.

To get some more details about ArcGIS visit,
http://www.esri.com/software/arcgis/index.html

To learn about ArcGIS API for Microsoft Silverlight/WPF visit,
http://resources.arcgis.com/content/arcgis-api-silverlightwpf/1.2/about

To learn about ArcGIS mapping for SharePoint visit,
http://www.esri.com/software/arcgis/mapping-sharepoint/index.html

Happy Coding.

Regards,
Jaliya

Monday, February 7, 2011

Basics of Client Object model in SharePoint 2010

When writing some applications for SharePoint 2010, I have noticed this nice thing called Client Object model. In here I am going to describe what Client Object model is per my understanding. Since I am a beginner for SharePoint please feel free to correct me if I am wrong.

SharePoint 2010 has introduced developers a nice concept called Client Object model which can be used to do variety of customizations in SharePoint. Previous versions of SharePoint such as SharePoint 2007 had no Client Object model available.

The main reason for Microsoft to introduce such a concept was, the developers need of different kind of Web Services that interacts with SharePoint and It’s not possible for Microsoft to Develop a Web Service per developer’s need. Even if Microsoft has provided a lot of Web Services that interacts with SharePoint, but because of the developer’s need of customized web services has made most of the out of the box web services unusable.

The most important part of using the client object model is developers can build remote clients without using the SharePoint out of the box Web services and without implementing the communication architecture.

Basically Client Object model enables developers to build solutions that consume SharePoint data and objects from applications that do not run on a SharePoint server. The best example would be a Silverlight application.
In Client Object Model Client can be in one of these type of applications.
  • Managed Client (Assembly File – Microsoft.SharePoint.Client)
  • Silverlight (Assembly File – Microsoft.SharePoint.Client.Silverlight)
  • ECMAScript (Assembly File – SP.js)
SharePoint 2010 client Object Model is written based on .Net CLR, so we can write custom code in C# or VB for SharePoint 2010 platform. For this we need following dlls , located at “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI” folder.
  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll

Similarities of SharePoint Client Object Model


Server (Microsoft.SharePoint)
Client Object Model
SPContext
ClientContext
SPSite
Site
SPWeb
Web
SPList
List
SPListItem
ListItem
SPField
Field


Please feel free to correct me and Give me your feedback.

Happy Coding.

Regards,
Jaliya

Monday, January 31, 2011

Moving into SharePoint 2010

SharePoint 2010!!!

Two months ago I had my first step into SharePoint and I had no idea what SharePoint is and what type of solutions SharePoint can deliver. Then I started learning SharePoint and as the time pass by I was really surprised with the features of SharePoint.

My first touch and feel version of SharePoint is SharePoint 2010, which was released in the first half of year 2010. Basically SharePoint is a Software Platform which provides Collaboration, Web content management, Documents management and many other features. The most important part of SharePoint is each of these features runs under one single platform.

For more information on SharePoint 2010 visit,

Happy Coding.

Regards,
Jaliya


Oops...Broken Links

It seems the free file hosting service I have been using has expired. So all the links are broken. I am sorry for that.

These are my new links,

For Syntax Highlighting C# Editor with an Inbuilt Compiler Version 1.0.0.1,

For Compile .cs file into .exe Version 1.0.0.1,

For Send Emails Easily using Gmail,

Happy Coding.

Regards,
Jaliya