Friday, 31 May 2013

Change the Web URL from Alternate Access Mappings using C#


There are many types of Zones available in the SharePoint access mappings.
  • Default
  • Intranet
  • Extranet
  • Internet
  • Custom 

Using this code you can change the alternate access mappings from Default to Internet.


            string webUrl = string.Empty;
            using (SPWeb web = workflowProperties.Site.RootWeb)
            {
                using (SPSite site = web.Site)
                {
                    foreach (Microsoft.SharePoint.Administration.SPAlternateUrl altUrl in site.WebApplication.AlternateUrls)
                    {
                        if (altUrl.UrlZone == Microsoft.SharePoint.Administration.SPUrlZone.Internet)
                            webUrl = altUrl.IncomingUrl .ToString() + site.ServerRelativeUrl.ToString();
                        //fullweburl = webUrl + site.ServerRelativeUrl.ToString();
                    }
                }
            }

Monday, 27 May 2013

Procedures for Creating XSLT Web part in a Page



1) Add a new web part zone found in ribbon using the Sharepoint Designer

2) On Insert ribbon you can find DataView dropdown Click and add Empty Data View

3) Now You can find a empty data view is added to the web part zone.

4) In the Empty Data view You can find Click Here to select a Data Source link available. Click it and choose the source of the data from which you wanted to add details Either List or Library.

5) Now on the Data Source details available on the right bottom corner you can find a button named "Insert Selected Field as.."
Click on it and weather you want to add single Item View or Multiple Item View.

6) Now on the Ribbon available on Options you can find Add/Remove Columns button. Click that.

7) Edit Columns popup will be available and you can find 2 sets of fields were available 

i) Available fields and

ii) Displayed Columns

8) Delete all the fields available in the Displayed Columns and Choose the fields you required from the available fields.


9) Click ok and you can see all the chosen fields available with the XSLT Web part.

Friday, 24 May 2013

Set or Get value people editor control in SharePoint with C#


Get People Editor Values


This code demostrate how to get people editor control values and insert a sharepoint list or document library.



SPWeb mySite = SPContext.Current.Web;
SPListItemCollection listItems = mySite.Lists["myList"].Items;

SPListItem item = listItems.Add();

item["Title"] = this.txtTitle.Text.ToString();
item["Location"] = this.lblLocations.Text.ToString();
item["EventDate"] = txtStart.SelectedDate ;

string[] UsersSeperated = pplEditor.CommaSeparatedAccounts.Split(',');
SPFieldUserValueCollection UserCollection = newSPFieldUserValueCollection();
foreach (string UserSeperated in UsersSeperated)
   {
    mySite.EnsureUser(UserSeperated);
    SPUser User = mySite.SiteUsers[UserSeperated];
    SPFieldUserValue UserName = new SPFieldUserValue(mySite, User.ID,                 User.LoginName);
    UserCollection.Add(UserName);
   }
item["people"] = UserCollection;
item.Update();



Set People Editor values from Sharepoint List or library


This code demostrate how to set people editor control values from  a sharepoint list


SPSite site = SPContext.Current.Site;
SPWeb myweb = site.OpenWeb();
SPList mylist = myweb.Lists["MyList"];
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='ID'/>" +
              "<Value Type='Text'>" + e.Value.ToString() + "</Value></Eq></Where>";

SPListItemCollection items = mylist.GetItems(query);
  foreach (SPListItem item in items)
    {

     try
      {

        this.txtTitle.Text = item["Title"].ToString();
        this.txtStart.SelectedDate =Convert.ToDateTime(item["EventDate"].ToString());
       }
        catch (Exception ex)
       {
         Response.Write(ex.Message.ToString());
       }


ArrayList _arrayList = new ArrayList();
SPFieldUserValueCollection users = item["People"asSPFieldUserValueCollection;
  if (users != null)
     {
       foreach (SPFieldUserValue user in users)
         {

          PickerEntity _pickerEntity = new PickerEntity(); // PickerEntitiy use using Microsoft.SharePoint.WebControls
          _pickerEntity.Key = user.User.LoginName;
          _pickerEntity.IsResolved = true;
          _arrayList.Add(_pickerEntity);
          }
        pplEditor.UpdateEntities(_arrayList);

      }
}  


Hide Top Bar, Ribbon, Quick Launch in SharePoint 2010

Top Bar, Ribbon, Quick Launch are come up with Application Pages by default. This could be done by using css.

Simple, Just add the below css Code in Application Page under PlaceHolderMain section.
<style type="text/css">
    #s4-ribbonrow.ms-cui-topBar2.s4-notdlg.s4-pr s4-ribbonrowhidetitle.s4-notdlg noindex#ms-cui-ribbonTopBars#s4-titlerow#s4-pr s4-notdlg s4-titlerowhidetitle#s4-leftpanel-content {display:none !important;}
    .s4-ca{margin-left:0px !importantmargin-right:0px !important;}
</style>
This will hide the elements and only the content will be shown.

To hide only Quick Launch Panel from the view

Add the following css code in the Application Page under PlaceHolderMain section.

<style type="text/css">
#s4-leftpanel{
display:none
}
.s4-ca{
margin-left:0px
}
</style>

Related article,

Hide quick launch at Sharepoint 2013

http://prasath04sharepoint.blogspot.in/2013/12/hide-quick-launch-in-sharepoint-2013.html