Archive for May, 2012

Developing a simple web part (.wsp) using WSPBuilder

Before we started the development, we have to install the WSPBuilder (SharePoint WSP tool), an extensions for Visual Studio. Just download the latest version here and install it. It is pretty easy steps.

Step 1: Create a new project on visual studio and then select the project type WSPBuilder  under C# programming language (I am using Visual Studio 2008).

Step 2: This is will create the following structure in the solution explorer.

Step 3: Right click on the project (WSPBuilderStepBiStep) and then add a new Item.

Step 4: This will give the following dialog box and then select WSPbuilder and Web Part Feature template. Enter the name and click Add button (I have given WebPartStepBiStep here)

Step 5: We will get the following dialog box and asking for the scope for this Web Part. I just modified the description and select the scope and then click OK.

Step 6: The solution explorer will look like this. Under the 12 hive folder you can see the Template and Features sub folders.

Step 7: Double click  on the WebPartStepBiStep.cs file and add your custom code on the right place. I just modifed the property like this:

public string MyProperty
        {
            get
            {
                if (_myProperty == null)
                {
                    _myProperty = "Hello Step Bi Step!";
                }
                return _myProperty;
            }
            set { _myProperty = value; }
        }

If you wanna to add a label rather than using this LiteralControl just replace the following code

this.Controls.Add(new LiteralControl(this.MyProperty));

with this

System.Web.UI.WebControls.Label label=new System.Web.UI.WebControls.Label();
label.Text = "Hello StepBiStep!";
this.Controls.Add(label);

Step 8: After replacing the code, the CreateChildControls() method will look like this:

        protected override void CreateChildControls()
        {
            if (!_error)
            {
                try
                {
                    base.CreateChildControls();
                    // Your code here...
                    System.Web.UI.WebControls.Label label=new System.Web.UI.WebControls.Label();
                    label.Text = "Hello StepBiStep!";
                    this.Controls.Add(label);
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }

Step 9: To build the project, just right click on the project name (WSPBuilderStepBiStep –> Build) and click Build.

Step 10: To build the WSP, Right click on the project name(WSPBuilderStepBiStep) –> WSPBuilder –> Build WSP

Step 11: This will create the .dll and .wsp files.


Step 12: To deploy the web part (.wsp file), right click on the project name(WSPBuilderStepBiStep) –> WSPBuilder –> Deploy


Step 13: You will get the following output, saying the .wsp file deployed successfully (done!).


Step 14: Go to the Web Part gallery and  populate the deployed Web Part on the New web part page.

Step 15: To use this Web Part in to your page, just follow these steps from my previous post. That’s all! Happy WSPBuilding..! 🙂

Please note: You have to run the Visual Studio as Administrator, otherwise you will get this error when you deploy the web part.

References:

1. http://rasor.wordpress.com/2008/10/12/wss-dev-quickstart/

Advertisement

, , , , , , , , , ,

2 Comments

How to add a custom web part to SharePoint 2007

Everyone knows about this, but I wanted to re-use this for my next series of custom web part posts. 🙂
I have already developed and deployed  the web part (WebpartStepBiStep.wsp) using STSADM command, you can see my previous post here. Now we will see the steps:

Step 1: On the SharePoint site, click Site Actions –> Site Settings –>Modify all site settings

Step 2: Site Settings page, click Web Parts under Galleries

Step 3: On the Web Part Gallery page, click New

Step 4:On the New Web Parts page, select the check box next to the Web Part that you want to add, and then click Populate Gallery

Step 5: Web part will be showing on the web part gallery.

Step 6: Click Site Actions, and then click Edit Page

Step 7: Click Add a Web Part

Step 8: In the Add Web Parts dialog box,  select the check box next to the Web Part that you want to add, and then click Add button

Step 9: The web part will be shown on your page.

Step 10: If you want modify the appearance and layout then Click Publish.

Step 11: That’s all, we are done.

Reference:
http://support.microsoft.com/kb/939306

, ,

2 Comments

Could not load file or assembly ‘CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304’ or one of its dependencies. The system cannot find the file specified.

I have developed a windows application which generates report using basic Crystal Reports in Visual Studio 2008. It was working fine in my development environment but on the client machine it was throwing this error message when I try to access the report.

When I click the details of the error message, I have got the following:

System.IO.FileNotFoundException: Could not load file or assembly 'CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
File name: 'CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304'
at DevInventory.InventoryReport.buttonPrint_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog]

After spending few hours I realized the Crystal Reports run time need to be installed to access the report on the client machine. You can find the instruction in the support website.

According to the environment (Visual Studio, 64 or 32 bits) , you can download the .msi packages from the SAP website OR you can find the package in your local drive (ie: C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\CrystalReports10_5).

Then install this into the client machine, that ‘s all!

Happy Reporting..! 🙂

References:

1. http://www.codeproject.com/Questions/127276/Crystal-report-doesnt-work-in-client-s-pc

2. http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=56787567

, ,

10 Comments