Wednesday, August 4, 2010

Difference Between .Net 4 Framework And .Net 4 Framework Client Profile

NET4 Client Profile is smaller and faster to install compared to the NET4 Full Framework (NET4 is 7-8MB smaller in size than the Full Framework), the main reasons are not just better deployment size/time but also:

•Reduce the Framework deployment failures.
•By keeping ASP.Net and other components (that are mostly needed for servers) out of the Client Profile, we can reduce the attack surface and the number of future servicing events which may be caused by server component (such as ASP.Net) and are not needed for desktop scenarios.
•Making NET4 Client Profile available on Windows Update will make sure that most desktop machines will include NET4 Client Profile over time and apps that target the Client Profile will not need to carry or install the Framework which will improve the overall deployment experience.
•Enable us to add features and grow the size of overall Framework in future versions but still have a smaller core.

Reference:

http://blogs.msdn.com/b/jgoldb/archive/2010/04/12/what-s-new-in-net-framework-4-client-profile-rtm.aspx

Stop Folder Sharing in Windows 7

Kindly follow below steps to stop sharing a folder in Windows 7

1.Open Computer Management. To do so, click Start, then right-click Computer, and then click Manage.

2.If the User Account Control dialog box appears, confirm that the action it displays is what you want, and then click Yes.

3.In the console tree, click System Tools, then click Shared Folders, and then click Shares.

4.In the details pane, right-click a shared folder, and then click Stop Sharing (this item only appears if you launched Computer Management using an account that is a member of the local Administrators group).

To stop sharing multiple files, press the CTRL key while clicking the file names, right-click any one of the selected files, and then click Stop Sharing. This removes shared network access to the selected files.

Reference

http://technet.microsoft.com/en-us/library/cc753475.aspx

Wednesday, June 2, 2010

Consume WCF Service Without creating Proxy ( Use of ChannelFactory Class)

In the old classic way, we used to refer the services using “Add Service reference” to the application and use the services. There are so many de-merits with this approach. One of them is, once we change the definition of the service, we have to update the service in the client layer.

To avoid this, we can use the ChannelFactory class. But how to use this class? Following sample may help us on this.

1. Create a Service Project WCFProxyService
2. Move the service Interface IService (ServiceContract) to another project, For this add a class library project called WCFContrcat and move the ServiceContract
3. Add Reference to the following assemblies
a. System.Runtime.Serialization
b. System.ServiceModel
4. Let us see the ServiceContract and DataContract code in this Interface

using System.Runtime.Serialization;
using System.ServiceModel;


// NOTE: If you change the interface name "IService" here, you must also update the reference to "IService" in Web.config.
[ServiceContract]
public interface IService
{

[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

// TODO: Add your service operations here
}

// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";

[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}

[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}


5. The implementation of the Service class will be as below

// NOTE: If you change the class name "Service" here, you must also update the reference to "Service" in Web.config and in the associated .svc file.
public class Service : IService
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}

public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}

6. Create the Client Project “WCFProxy” and refer the “WCFContract” project to this project.
7. Modify the App.config file, Configuration section as below



8. Now add a new class “ProxyHelper.cs” to the Client Project “WCFProxy”
Use of this class is to create the Proxy on the fly.
9. Following is the code will help us to create the proxy on the fly using ChannelFactory class

using System.ServiceModel;

namespace WCFProxy
{
public class ProxyHelper
{
IService channel = null;
ChannelFactory factory = null;

public ProxyHelper()
{
factory = new ChannelFactory("WSHttpBinding_IService");
channel = factory.CreateChannel();
}

public string GetData()
{
string value = channel.GetData(1);
factory.Close();
return value;
}

public CompositeType GetDataUsingDataContract(CompositeType cType)
{
CompositeType returnType = channel.GetDataUsingDataContract(cType);
factory.Close();
return returnType;
}


}
}


10. Add reference to the same two Assemblies as specified in step 3
11. Please check the above code, how the ChannelFactory is used to call the service methods
12. Using the Helper class we can call the service methods

Usally this helper class will be used as the Proxy class, that dynamically create the proxy at Runtime. Below is the code shows the way Helper class is being used.

ProxyHelper pHelper=new ProxyHelper();
MessageBox.Show(pHelper.GetData());

CompositeType cType = new CompositeType();
cType.BoolValue = true;

cType.StringValue = "Arun ";

pHelper = new ProxyHelper();
cType = pHelper.GetDataUsingDataContract(cType);

MessageBox.Show(cType.StringValue);

Hope the above will help and will improve the maintainability of your application.

Tuesday, May 25, 2010

JQuery For VS 2008

What is Jquery?

jQuery is a library written using JavaScript and created by
Jquery team.

How to use JQuery in VS 2008 ?

1. Download JQuery from the JQuery site 2. Download both the .js and -vdsoc.js file. Ex. if you are using Jquery Version 1.4.1. Then download both jquery-1.4.1.js (JQuery Library) and jquery-1.4.1-vsdoc.js (jQuery VS 2008 Intellisense documentation) file. The -vsdoc.js file is for the intellisense support. 3. Make sure the we have installed the hotfix for the VS2008. If not please download from hotfix-url and install it 4.
Open Visual Studio 2008 > File > New > Website > Choose ‘ASP.NET 3.5 website’ from the templates > Choose your language (C# or VB) > Enter the location > Ok. In the Solution Explorer, right click your project > New Folder > rename the folder as ‘Scripts’.
Right click the Scripts folder > Add Existing Item > Browse to the path where you downloaded the jQuery library (jquery-1.2.6.js) and the intellisense documentation (jquery-1.2.6-vsdoc.js) > Select the files and click Add.

Now drag and drop the jquery-1.2.6.js file from the Solution Explorer on to your page to create a reference.

Note: Since you have applied the hotfix, you do not have to manually add a reference to the jquery-1.2.6-vsdoc.js file in your page. Once the reference to the runtime library has been added, Visual Studio automatically searches for the ‘vsdoc’ file and loads it. You just need to keep both the runtime library and the documentation file next to each other.
Else use following line of code as shown in the figure below to get the intellisense in VS 2008

To test intellisense, add a script
block and key in ‘$(‘. You will get an intellisense.

Example 1 – Display an alert on asp:Button click using jQuery
Add a Button element to the page as shown below:
<asp:Button ID="Button1" runat="server" Text="Button" />
Now in order to tell the browser to perform some action using jQuery as soon as the document is ready or loaded, use this block:
<script type="text/javascript">
$(document).ready(function() {
// add code here
});
script>
Add your code in the function block
<script type="text/javascript">
$(document).ready(function() {
$("#Button1").click(function() {
alert("Hello world!");
});
});
script>

Reference URL : Using jQuery with ASP.NET - A Beginner's Guide

Monday, February 1, 2010

Creating Lists using Sharepoint Object Model

  1. Open Visual Studio. Create a new Windows Forms project.
  2. Add a textboxes, one to accept the name of the site collection and another to accept the name of the new site to be created under the site collection.
  3. Add a button that creates the new site.
  4. Add reference to Microsoft.Sharepoint dll. This dll is represented by the name Windows Sharepoint Services in the Add Reference dialog box.
  5. Add the namespace of Microsoft.Sharepoint dll like this.
    • using Microsoft.Sharepoint;
  6. In the button click event, open the site collection.
    • SPSite siteCollection = new SPSite(txtSiteCollectionUrl.Text);
  7. Now open the top level site of the site collection.
    • SPWeb site = siteCollection.OpenWeb();
    • If you want to open a different site under the site collection other than the top level site, you can use the overloaded methods of the OpenWeb() method that accepts the name of the site as argument.
  8. The Lists property present in the SPWeb object will return all the lists that are present in that site as an SPListCollection object
    • SPListCollection listCollection = site.Lists;
  9. In order to add a new list, use the add method of the SPListCollection object.
    • listCollection.Add(“listname”, “list description”, SPListTemplateType.GenericList);
    • Note that the third argument accepts the template in which the list should be created. GenericTemplate represents the custom list. We can choose the template we need from the SPListTemplateType enum.
  10. Close and dispose and the site and site collection
    • site.dispose();
    • siteCollection.close();

The complete code can be found below..

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

SPSite siteCollection;
SPWeb site;

private void btnCreateSite_Click(object sender, EventArgs e)
{

try
{
siteCollection = new SPSite(txtSiteCollection.Text);
site = siteCollection.OpenWeb();
SPListCollection listCollection = site.Lists;

listCollection.Add(txtListName.Text, “list description”, SPListTemplateType.GenericList);
}
catch (Exception)
{ }
finally
{
site.Dispose();
siteCollection.Close();
}
}

}
}

Creating Sites using Sharepoint Object Model


MOSS 2007 provides rich set of API’s that allows developers to programatically accomplish almost everything that can be done in sharepoint. Sharepoint Object Model comes with 10 different dll’s comprising 30 namespaces.

The aim of this post is to show the sharepoint object model to create a new sharepoint site programatically.

Before start, lets look at the sharepoint site structure in the following diagram.

SiteArchitecture



Each layer in the above architecture diagram is represented by an object in the sharepoint object model. The object mapping is represented in the following table.
Sharepoint Site Architecture Component Object in Sharepoint Object Model

Sharepoint Site Architecture Component Object in Sharepoint Object Model
Site Collection SPSite
Site SPWeb
List Collection SPListCollection
List SPList
List Field Collection SPFieldCollection
List Field SPField
List Item Collection SPListItemCollection
List Item SPListItem


Steps to create a new Sharepoint Site:

1. Open Visual Studio. Create a new Windows Forms project.
2. Add a textboxes, one to accept the name of the site collection and another to accept the name of the new site to be created under the site collection.
3. Add a button that creates the new site.
4. Add reference to Microsoft.Sharepoint dll. This dll is represented by the name Windows Sharepoint Services in the Add Reference dialog box.
5. Add the namespace of Microsoft.Sharepoint dll like this.
* using Microsoft.Sharepoint;
6. In the button click event, open the site collection.
* SPSite siteCollection = new SPSite(txtSiteCollectionUrl.Text);
7. Now open the top level site of the site collection.
* SPWeb site = siteCollection.OpenWeb();
* If you want to open a different site under the site collection other than the top level site, you can use the overloaded methods of the OpenWeb() method that accepts the name of the site as argument.
8. SPWeb object has a property called ‘Webs’ that contains a collection of all the sites present under that site.
9. Inorder to add a new site, use the following code.
* site.Webs.Add(txtSiteName.Text, txtSiteName.Text, Convert.ToUInt32(1033),site.WebTemplate, , false,false);
10. Close and dispose and the site and site collection
* site.dispose();
* siteCollection.close();

The complete code can be found in this file.using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

SPSite siteCollection;
SPWeb site;

private void btnCreateSite_Click(object sender, EventArgs e)
{

try
{
siteCollection = new SPSite(txtSiteCollection.Text);
site = siteCollection.OpenWeb();
site.Webs.Add(txtSiteName.Text, txtSiteName.Text,
txtSiteName.Text + ” Desc”, Convert.ToUInt32(1033), site.WebTemplate,
false, false);
}
catch (Exception)
{ }
finally
{
site.Dispose();
siteCollection.Close();
}
}

}
}