Friday, December 24, 2010

Public Property of User Control with Visual Web Part of SharePoint 2010

Problem:
I have tried to pass a string to a public property in User control which is registered in Visual Web Part but when i write UserControl1. , Visual Studio intellisense can't see this property so what i Have to do?

Solution:
For example ,In case you have a user control called "UserControl1" with public property called "Message" and Label Control to display this message in page load event as following :

UserControl1.ascx

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UserControl1.ascx.cs" Inherits="SharePointProject1.ControlTemplates.SharePointProject1.UserControl1" %>
<asp:Label ID="lblMessage" runat="server" />

UserControl1.ascx.cs

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace SharePointProject1.ControlTemplates.SharePointProject1
{
    public partial class UserControl1 : UserControl
    {
        public string Message { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            lblMessage.Text = Message;
        }
    }
}

Now I want to register this usercontrol in the Visual Web Part and Create a Property called "Message" which the user can enter the value by edit the web part in the sharePoint page then insert the string and after that save the web part.
Then we can pass this value to a property (Message) of UserControl as following :

VisualWebPart1UserControl.ascx
so here we have added and registered the User control in the Visual Web Part

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="SharePointProject1.VisualWebPart1.VisualWebPart1UserControl" %>
<%@ Register src="../UserControl1.ascx" tagname="UserControl1" tagprefix="uc1" %>

<uc1:UserControl1 ID="UserControl11" runat="server" />

VisualWebPart1.cs
so here we defined a property called a Message and we assigned the Current Webpart instacne object to the userControl  (control.currWebPart).

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SharePointProject1.VisualWebPart1
{
    [ToolboxItemAttribute(false)]
    public class VisualWebPart1 : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/SharePointProject1/VisualWebPart1/VisualWebPart1UserControl.ascx";

        protected override void CreateChildControls()
        {
            VisualWebPart1UserControl control = Page.LoadControl(_ascxPath) as VisualWebPart1UserControl;

            if (control != null)
            {
                control.currWebPart = this;
            }
            Controls.Add(control);
        }

        [System.Web.UI.WebControls.WebParts.WebBrowsable(true),
        System.Web.UI.WebControls.WebParts.WebDisplayName("Message String"),
        System.Web.UI.WebControls.WebParts.Personalizable(),
        System.ComponentModel.Category("Settings")]
        public string Message { get; set; }
    }
}

VisualWebPart1UserControl.ascx.cs
Last we assigned the value of currWebPart.Message to the property of User control.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using SharePointProject1.ControlTemplates.SharePointProject1;

namespace SharePointProject1.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        public VisualWebPart1 currWebPart { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            ((UserControl1)UserControl11).Message = this.currWebPart.Message;
        }
    }
}

Done.

Wednesday, December 15, 2010

Error in SharePoint Designer 2010 with WCF -The server could not complete your request

I have tried to open my web application in SharePoint Designer 2010 but unfortunately i got the following error :

The server could not complete your request.

For more specific information , click the Details button (there are nothing :)) so i have solved this error by open the web.config then go to

<system.serviceModel>
which related to WCF and then remove the below tags .

<behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>

Done.

Monday, December 13, 2010

SQL Server 2008 in Windows Server 2008 R2 (SlipStream method)

During these days i have tried to install SQL Server 2008 Failover cluster in Windows Server 2008 R2 but i have faced many problems when i try to install SQL Server 2008 with SP1 or SP2 and these error like "There wan an error setting private property RequireKerberos to value 1 for resource ..." , "Network Name already exists" so i search for the solution in the internet and i found this is way to fix the above problem by using SlipStream method
http://blogs.msdn.com/b/petersad/archive/2009/03/02/sql-server-2008-basic-slipstream-steps.aspx
http://blogs.msdn.com/b/petersad/archive/2010/10/14/creating-a-merged-slipstream-drop-containing-sql-server-2008-rtm-and-service-pack-2.aspx

and these are the steps for basic Slipstream :
Extract SP1 to folder c:\SP1 by using this command

SQLServer2008SP1-KB968369-x64-ENU.exe /x:C:\SP1
then run MSI file go to C:\SP1\x64\setup\1033\sqlsupport.msi
finally run this command
setup.exe /PCUSource=C:\SP1 and continue as normal steps.
Done

Thursday, December 9, 2010

SQL Server "Denali" Community Technology Preview (CTP) version - No-Reboot package is found on Windows 7/Windows Server 2008 R2 or higher

I have tried to install SQL Server 2011 CTP 1 in my Windows 7 64 bit from this link and i got this error while SQL Server Check the rules " No-Reboot package is found on Windows 7/Windows Server 2008 R2 or higher"

so to pass this rule you have to install the following updates and then restart the windows
"Microsoft .NET Framework 3.5 SP1 Update for Windows 7 and Windows Server 2008 R2 for x64-based Systems"

and then re-run SQL Server installation wizard and it will pass successfully.


after i have finish from the installation and opened SQL Server Management Studio i notice first new thing is SQL Server Management Studio that became as Visual Studio 2010 with thier feature debugging , movable tab....