Showing posts with label Sharepoint. Show all posts
Showing posts with label Sharepoint. Show all posts

Sunday, October 20, 2013

How to Remove an Assembly from GAC using gacutil in Windows Server 2008 r2 (Without using .net sdk)

Hi all, I happened to remove some unwanted dlls from the GAC in a production server. In this server I didn't have windows SDK installed and therefore I had to use some other method to use gacutil.

The first thing I did was to copy the gacutil and it's configuration file from my local machine. It's located in C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bin\.  Copy the gacutil Application and gacutil.exe CONFIG file from there and paste it to a folder in your Server. 

When you want to install  an assembly to GAC, copy the above files to your assembly location and open the cmd as an Administrator. Then run the command "gacutil -i <assembly_name>" to install the assembly.

To uninstall an assembly from GAC you have to use "gacutil -u" command. As gacutil is now in a sepereate folder in your server, redirect to that location from the cmd and use the above command. Here you have to use the fully qualified name of the assembly in the GAC. Following is an example. 

gacutil -u "hello,Version=1.0.0.0, Culture=neutral, PublicKeyToken=0123456789ABCDEF"

When you uninstall the assembly, you'll get an error message including this line. 

"Unable to uninstall: assembly is required by one or more applications"

To solve this follow the instructions as follow. 


  1. cd %systemroot%\assembly\
  2. cd gac_msil (Fom here you may have more that one "gac" directory, so you will have to search within each to find your component.  For me, it is within the "gac_MSIL" directory.)
  3. cd <assembly DLL name>
  4. cd <assembly version number>__<public key token>                                                            
    1. For example: 1.0.23.456__10dbd0fba6984148
  5. erase *.*
  6. Say "y" to are you sure.
  7. cd ..
  8. rd <assembly version number>__<public key token>
  9. cd ..
  10. rd <assembly DLL name>

Tuesday, May 21, 2013

How to use a List Definition for Sharepoint 2010 in VS 2010

When creating a list definition you have to create and edit two main files. They are the Elements.xml and Schema.xml. In the Elements.xml you have to add the <Fields> and <Content Type> elements. Then in the Schema.xml you have to refer them.

When creating the GUIDs for the Fields and Content types, you have to be careful because they have to be inherited. Then those GUIDs can be created using Tools-> Create GUID-> New-> 4th Option

This is the MSDN reference for creating a List Definition.
List Instances are the objects that can be used for creating instances of the list definition.

Update:

You can only change the schema.xml to create the List Definition. There first you have to add the <Content Type> then the <Fields> and <FiledRef>s. After that, in the <ViewFields> you can add the <FieldRefs> to determine, which <Fileds> should be viewed.
When creating the GUID for the content type ID you have to be careful. There you have to add the correct Item ID (You can find them in  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\ctypes\ctypes.xml).

To create the ID for the Content Type, first add the ItemID (Eg: 0x01 for ContentTypes) then add the GUID without the hyphens. For FieldRef IDs also there are default IDs for fields like Title. They can be found in the wss xmls in the 14\TEMPLATE\FEATURES folder. As an example, field ID for the title field is fa564e0f-0c70-4ab9-b863-0177e6ddd247.

Update:

Filed Type IDs are here:


C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\fields\fieldswss3.xml

Issues and Solutions for Sharepoint 2010 - Enable Session State Issue

This issue arises due to missing or removing session element. For that just verify whether the "enableSessionstate" is set to "true" and add the following line in the httpmodules in web.config file.

1) <pages enableSessionState="true" enableViewState="true" enableViewStateMac="true"/>
2) <add name="Session" type="System.Web.SessionState.SessionStateModule" />

If this doesn't work check whether "Session" is removed somewhere like this,
<remove name="Session" />.

If so add the 2nd line again after that. 
For a detailed article visit this blog. 

Monday, May 20, 2013

How to Get User Emails from Sharepoint 2010 using People Editor

This code shows few options on selecting users from sharepoint site and retrieving their mails using people editor web control

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;
using System.Data;
using System.Collections;

namespace CustomPeoplePickerOne.PeoplePicker_swp_1
{
    [ToolboxItemAttribute(false)]
    public class PeoplePicker_swp_1 : WebPart
    {
        PeopleEditor pe = null;
        SPWeb web = null;
        protected override void CreateChildControls()
        {
            web = SPContext.Current.Web;

            pe = new PeopleEditor();
            pe.ValidatorEnabled = true;
            this.Controls.Add(pe);

            Button viewPeople = new Button();
            viewPeople.Text = "View";
            viewPeople.Click += new EventHandler(viewPeople_Click);
            this.Controls.Add(viewPeople);
                 
        }

        void viewPeople_Click(object sender, EventArgs e)
        {
            viewPeopleOption4();
        }

        void viewPeopleOption() 
        {
            foreach (var loginName in pe.CommaSeparatedAccounts.Split(';', ','))
            {
                SPUser user = SPContext.Current.Web.EnsureUser(loginName);
                TextBox tb = new TextBox();
                tb.Text = string.Format("Name : {0} Email : {1}", user.Name, user.Email);
                this.Controls.Add(tb);
            }
        }

        void viewPeopleOption2() 
        {
            //Create the data table and add data to it
            DataTable dt = new DataTable();
            dt.Columns.Add(new DataColumn(" Name ", typeof(String)));
            dt.Columns.Add(new DataColumn(" Email ", typeof(String)));

            //get data from the people editor
            for (int i = 0; i < pe.ResolvedEntities.Count; i++)
            {
                string accName = "";
                string email = "";
                PickerEntity pickerEntity = (PickerEntity)pe.ResolvedEntities[i];
                Hashtable hsEntityData = pickerEntity.EntityData;
                if (hsEntityData.ContainsKey("Account Name"))
                {
                    accName = Convert.ToString(hsEntityData["Account Name"]);
                }
                else
                {
                    accName = "Not available";
                }
                if (hsEntityData.ContainsKey("Email"))
                {
                    email = Convert.ToString(hsEntityData["Email"]);
                }
                else
                {
                    email = "Not available";
                }


                TextBox tb = new TextBox();
                tb.Text = string.Format("Name : {0} Email : {1}", accName, email);
                this.Controls.Add(tb);

            }
        }

        void viewPeopleOption3() 
        {
            var accountName = pe.Accounts[0];
            SPUser user = web.EnsureUser((string)accountName);

            Label userLable = new Label();
            userLable.Text = string.Format("User : {0} Email : {1}",user.Name,user.Email);
            this.Controls.Add(userLable);

        }

        void viewPeopleOption4() 
        {
            if (pe.IsValid)
            {
                for (int i = 0; i < pe.ResolvedEntities.Count; i++)
                {
                    PickerEntity picker = (PickerEntity)pe.ResolvedEntities[i];
                    Hashtable hstEntityData = picker.EntityData;
                    string[] name = picker.DisplayText.Split(' ');
                    string Email = Convert.ToString(hstEntityData["Email"]);
                    //string FName = name[0].ToString();
                    //string SName = (name[1].ToString() != null) ? name[1].ToString() : "";
                    Label userLable = new Label();
                    userLable.Text = Email;
                    this.Controls.Add(userLable);

                }
            }
        }
    }
}