Wednesday, February 15, 2012

Rendering HTML and Multiple HyperLink inside SPGridView

Sometimes we need to include HTML formatted data within some fields of SPGridView. I have worked on one requirement in which I have to include multiple Hyperlinks into one field of HTML in which I have written like “<a>” , and when SPGridView renders it shows entire HTML Code, not hyperlinks.

An easy way around this is to set the HTMLEncode property to false. By default this property is set to true, which will encode your HTML so that it will show up as code, changing <’s and >’s into &lt; and &gt;, and so on.

Sample Code:

#region Create Child Controls
protected override void CreateChildControls()
{
    try
    {

        grdData = new SPGridView();
        grdData.AutoGenerateColumns = false;

        BoundField colTitle = new BoundField();
        colTitle.HeaderText = "Title";
        colTitle.HtmlEncode = false; //This is the line
        colTitle.DataField = "Title";
        this.grdData.Columns.Add(colTitle);

       

        this.Controls.Add(this.grdData);

    }
    catch (Exception ex)
    {
    }
}
#endregion


Enjoy!!!

Thursday, February 2, 2012

Get Value of QueryString from SharePoint Event Receiver

Hello Friends

From SharePoint Event Receivers how could we get the value which has been passed from querystring? 

How can we achieve this? Here is the sample of code.

public class AddData: SPItemEventReceiver
    {
        System.Web.HttpContext httpContext = null;

        /// <summary>
        /// An item was added.
        /// </summary>
        public AddData ():base()
         {
                 //get the httpContext in contsructor, we won't get
                 //this outside of this constructor
             try
             {

                 httpContext = System.Web.HttpContext.Current;
             }
             catch (Exception Ex)
             {
             }
        }

public override void ItemAdding(SPItemEventProperties properties)
        {
                if (httpContext != null)
                {
                    if (httpContext.Request.QueryString["Data"] != null)
                    {
                                                String strData= httpContext.Request.QueryString["Data "].ToString();
}

                }
            }
}


Enjoy coding!!!
Disha Shah

Wednesday, February 1, 2012

“Access Denied” : Add an assembly to the Global Assembly Cache on Windows Server 2008 R2

Hello friends

I encountered one error when I was trying to deploy DLL to GAC, it always throws error “Access Denied” , it was really frustrating. The problem was UAC(User Account Control)  which does not allow to deploy to GAC.
I tried below things to solve problem, BUT all failed

1>      Start a cmd prompt with “Run as administrator” and they typing the “explorer” GAC window and from where DLL we need to deploy and tried to deploy there still same error.
2>      “Disable” UAC. FAIL

I have checked about the Local Polices related GAC.

Here is an entire list of local policies related to UAC.



User Account Control: 

Run all administrators in Admin Approval Mode. It was Enabled on their server. It means that any action that should only be achievable by an administrator must go through UAC’s “Admin Approval”. 

Now we need to “disabled” this means  that Admin Approval Mode is no longer required for members of the local Administrators group… effectively disabling UAC entirely for those users.













Then I Rebooted (required changes to the local security policy).


Now it works…Hip Hip Hurray.

IMPORTANT: Disabling this can make it easier for malware to compromise your system. I encourage this to be disabled only temporarily so that the specific actions required may be taken, then re-enabled (along with the associated reboot) immediately at completion.

  Thanks
Disha Shah