Blogger

  • This email address is being protected from spambots. You need JavaScript enabled to view it.

    Recent items

Login

Luca Costante

Luca Costante

Have you ever written a timer job in SharePoint to read from or writing to a term store in Managed Metadata, you might have done so and faced the error:
"The current user has insufficient permissions to perform this operation"
Even if you try to run the code with SPSecurity.RunWithElevatedPrivileges(), or with your own account from Visual Studio, it will still give you the same problem.
The thing is, that the timer job runs with its own service, which is “SharePoint 2010 Timer”, see the below image.

The user running this service has to have access to the term store administrators in Central Administration, see the image below:

 

In SharePoint 2010, there is a WCF service utilizing ADO.NET Data Service called ListData.svc fulfilling this goal.  You can submit the query by providing the URL containing various commands like sorting, filtering, positioning....etc. 

List all objects of the site
http:/<sp>/_vti_bin/ListData.svc

List all items of the list
http://<sp>/_vti_bin/ListData.svc/ListName

List specific item of the list
http://<sp>/_vti_bin/ListData.svc/ListName(<index>)

List specific item's field value of the list
http://<sp>/_vti_bin/ListData.svc/ListName(<index>)/(<field>)

Filtering
http://<sp>/_vti_bin/ListData.svc/ListName?$filter=<field> <operator> <value>

Lookup field query
http://%3csp%3e/_vti_bin/ListData.svc/ListName?$expand=<LookupList>&$filter=<LookupList>/<LookupField> <operator> <value>

Range (example: getting from 20th to 25th products)
http://<sp>/_vti_bin/Products?$skip20&$top=5


Check MSDN Reference Using Microsoft ADO.NET Data Services for all query options(expand, orderyby, skip, top, filter), operators (eq, ne, gt, ge, lt, le, and, or, not.....), and functions.

In my case, I've used ListData.svc to retrive items from a list. It works fine when I used as filter a field with one word as display name but when I used a field with two or more words as display name I receive this error 400 Bad Request and with Fiddler I inspect the request and view the error:

Show/Hidden xml code

View source
 
 
 
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
    <code/>
    <message xml:lang="it-IT">Syntax error at position 10.</message>
</error>
 
 
 

This is the request: "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith(Model Year,'mo')&$select=Model Year,Id".

Trying to resolve the problem, I've tested:

  • Use the single quote for the display name "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith('Model Year','mo')&$select='Model Year',Id": DOES NOT RESOLVE THE PROBLEM
  • Use the double quote for the display name "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith("Model Year",'mo')&$select="Model Year",Id": DOES NOT RESOLVE THE PROBLEM
  • Use the internal name of the field "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith(OMG_ModelYear,'mo')&$select=OMG_ModelYear,Id": DOES NOT RESOLVE THE PROBLEM
  • Use the display name removing the space from words "http://test.virtualsp.com/_vti_bin/ListData.svc/Omologations?$filter=startswith(ModelYear,'mo')&$select=ModelYear,Id": THIS RESOLVES THE PROBLEM

So, when you want use the ListData.svc and your fields display name has spaces, REMEMBER to remove it into the request and see this beautiful page.

Sometimes, the customer asks us to implement a particular field. In my case, the task is to have a field that show an editable table.


The specialness of this table is that it has only two editable columns but the editor can choices to add a different number of rows: this means that I need to implement a custom field that has an update panel that incapsule an asp Table.  For each row of the table, I must add two TextBox. Also there must be an "Add" button to add another row with other two text field.

To implement all, I need to define:

  • the xml (fldtypes_FeatureBenefitField.xml) to describe the field
  • the Field definition (FeatureBenefitField.cs): it extends the functionality of the SPFieldMultiColumn
  • the field control  (FeatureBenefitFieldControl.cs) that has the logic to manipulate the field
  • the render template (FeatureBenefitTemplateRender.ascx) that is the ascx that describes how render the field. I've defined two render template: one for the the creation and the edit of the item, another one for the view. Note: this file must be stored under the CONTROLTEMPLATES root mapped folder

 
A problem that I've found during the implementation is that when I interact with other fields or when I press on the add button, the values are lost. The workaround is to store into a property of the ViewState the number of row so I can reproduce the table and to restore the previous values I read the values into the Request.Form.
Another problem is that when I modify the renderTemplate and I make a deploy with Visual Studio, I don't see the updates. The problem is that when I deploy with Visual Studio, it makes only a Recycle of the Application Pool and the previous version of the template is still in use by SharePoint. So to resolve the problem, the keyword is "iisreset".
After the iisreset, the updated version of the render template is shown.

Here the code of the customization.

fldtypes_FeatureBenefitField.xml

Show/Hidden xml code

View source
 
 <?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
    <FieldType>
        <Field Name="TypeName">FeatureBenefitField</Field>
        <Field Name="TypeDisplayName">Feature Benefit</Field>
        <Field Name="TypeShortDescription">Feature Benefit field that show an editable table</Field>
        <Field Name="ParentType">MultiColumn</Field>
        <Field Name="FieldTypeClass">LucaCostante.SP.CF.FeatureBenefitField,LucaCostante.SP.CF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=2cdef4b45abd6dec</Field>
        <Field Name="Sortable">TRUE</Field>
        <Field Name="Filterable">TRUE</Field>
        <Field Name="AllowBaseTypeRendering">TRUE</Field>
    </FieldType>
</FieldTypes>
 

FeatureBenefitField.cs

Show/Hidden csharp code

View source
 
 
 
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Security;
using System.Security.Permissions;
 
namespace LucaCostante.SP.CF
{
    public class FeatureBenefitField : SPFieldMultiColumn
    {
        public FeatureBenefitField(SPFieldCollection fields, string fieldName) 
            : base(fields, fieldName) { }
 
        public FeatureBenefitField(SPFieldCollection fields, string typeName, string displayName) 
            : base(fields, typeName, displayName) { }
 
        public override object GetFieldValue(string value)
        {
            if (string.IsNullOrEmpty(value))
                return null;
            return new SPFieldMultiColumnValue(value);
        }
 
        public override BaseFieldControl FieldRenderingControl
        {
            [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            get
            {
                BaseFieldControl fieldControl = new FeatureBenefitFieldControl();
                fieldControl.FieldName = this.InternalName;
                return fieldControl;
            }
        }
        
    }
}
 
 
 

FeatureBenefitFieldControl.cs

Show/Hidden csharp code

View source
 
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Security;
using System.Security.Permissions;
using System.Collections;
using Microsoft.SharePoint;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using LucaCostante.SP.CF.CONTROLTEMPLATES;
 
namespace LucaCostante.SP.CF
{
    public class FeatureBenefitFieldControl : BaseFieldControl
    {
        private int numOfRows = 1;
 
        protected Table tableFeatBenefit;
        protected Table tableView;
        protected Button addButton;
 
 
        #region Properties
        protected override string DefaultTemplateName
        {
            get
            {
                if (this.ControlMode == SPControlMode.Display)
                {
                    return this.DisplayTemplateName;
                }
                else
                {
                    return "FeatureBenefitTemplate";
                }
            }
        }
 
        public override string DisplayTemplateName
        {
            get
            {
                return "FeatureBenefitTemplateForDisplay";
            }
            set
            {
                base.DisplayTemplateName = value;
            }
        }
 
        public override object Value
        {
            get
            {
                EnsureChildControls();
 
                GenerateTable();
                return GenerateCurrentFeatureBenefitValue();
            }
            set
            {
                EnsureChildControls();
                InitControls(value.ToString());
            }
        }
 
 
        #endregion
 
        #region Protected Methods
        protected override void CreateChildControls()
        {
            try
            {
                if (this.Field != null)
                {
                    base.CreateChildControls();
                    this.BindControls();
                }
 
                if (this.ControlMode == SPControlMode.New)
                {
                    if (!this.Page.IsPostBack)
                        this.InitControls();
                    else
                        this.EnsureChildControls();
                    this.AssignEvents();
                }
                else if (this.ControlMode == SPControlMode.Edit)
                {
                    if (!this.Page.IsPostBack)
                        this.InitControls();
                    this.EnsureChildControls();
                    this.AssignEvents();
                }
                else if (this.ControlMode == SPControlMode.Display)
                {
                    this.EnsureChildControls();
                    ViewTable();
                }
               
            }
            catch (Exception ex)
            {
                if (ex.GetType().Equals(typeof(SPFieldValidationException)))
                    throw new SPFieldValidationException(ex.Message);
 
            }
 
        }
 
       
        #endregion
 
 
 
        #region Private Methods
        private void BindControls()
        {
            if (this.ControlMode == SPControlMode.Display)
            {
                this.tableView = (Table)TemplateContainer.FindControl("tbl_FeatureBenefitForDisplay");
            }
            else
            {
                this.tableFeatBenefit = (Table)TemplateContainer.FindControl("tbl_FeatureBenefit");
                this.addButton = (Button)TemplateContainer.FindControl("btn_Add");
            }
        }
 
        private void AssignEvents()
        {
            this.addButton.Click += new EventHandler(lbtnAddButton_Click);
        }
 
        private void InitControls()
        {
            try
            {
                EnsureChildControls();
                GenerateTable();
            }
            catch (Exception ex)
            {
                if (ex.GetType().Equals(typeof(SPFieldValidationException)))
                    throw new SPFieldValidationException(ex.Message);
            }
        }
 
        private void InitControls(string couples)
        {
            string[] couple = couples.Split(new char[]{';','#'},StringSplitOptions.RemoveEmptyEntries);
            this.numOfRows = couple.Length;
            ViewState["RowsCount"] = this.numOfRows;
            GenerateTable();
 
            for (int i = 0; i < couple.Length; i++)
            {
                string[] currentCouple = couple[i].Split(new char[] { '€', 'ç' }, StringSplitOptions.RemoveEmptyEntries);
                if (currentCouple != null && currentCouple.Length > 0)
                {
                    ((TextBox)this.tableFeatBenefit.Rows[i+1].Cells[0].Controls[0]).Text = currentCouple[0];
                    ((TextBox)this.tableFeatBenefit.Rows[i+1].Cells[1].Controls[0]).Text = currentCouple[1];
                }
            }
 
        }
 
 
        private SPFieldMultiColumnValue GenerateCurrentFeatureBenefitValue()
        {
            SPFieldMultiColumnValue returnValue = new SPFieldMultiColumnValue(tableFeatBenefit.Rows.Count-1);
 
            for (int i=1;i< tableFeatBenefit.Rows.Count;i++)
            { 
                string feature=((TextBox) tableFeatBenefit.Rows[i].Cells[0].Controls[0]).Text;
                string benefit=((TextBox) tableFeatBenefit.Rows[i].Cells[1].Controls[0]).Text;
 
                if (!string.IsNullOrEmpty(feature) && !string.IsNullOrEmpty(benefit))
                    returnValue[i-1] = string.Format("{0}€ç{1}",feature,benefit);
            }
 
            return returnValue;
        }
 
        protected void lbtnAddButton_Click(object sender, EventArgs e)
        {
            ViewState["RowsCount"] = ++numOfRows;
            GenerateTable();
        }
 
        #endregion
 
 
       
 
        #region manipulate table
 
 
        private void ViewTable()
        {
            var value = SPContext.Current.Item[this.FieldName];
 
            if (value!=null)
            { 
                 TableRow row = null;
                 TableCell cell = null;
                
                row = new TableRow();
                cell = new TableCell();
                cell.ID = "FeatureHR";
                cell.Text = "Feature";
                row.Cells.Add(cell);
                cell = new TableCell();
                cell.ID = "BeneitHR";
                cell.Text = "Benefit";
                row.Cells.Add(cell);
                this.tableView.Rows.Add(row);
 
 
                string[] couple = value.ToString().Split(new char[] { ';', '#' }, StringSplitOptions.RemoveEmptyEntries);
                this.numOfRows = couple.Length;
 
                for (int i = 0; i < couple.Length; i++)
                {
                    string[] currentCouple = couple[i].Split(new char[] { '€', 'ç' }, StringSplitOptions.RemoveEmptyEntries);
                    if (currentCouple != null && currentCouple.Length > 0)
                    {
                        row = new TableRow();
 
                        cell = new TableCell();
                        cell.Text = currentCouple[0];
                        row.Cells.Add(cell);
                        cell = new TableCell();
                        cell.Text = currentCouple[1];
                        row.Cells.Add(cell);
 
                        this.tableView.Rows.Add(row);
                    }
                }
            }
 
        }
 
        private void GenerateTable()
        {
            if (ViewState["RowsCount"] != null)
                numOfRows = Convert.ToInt32(ViewState["RowsCount"].ToString());
 
 
            TableRow row = null;
            TableCell cell = null;
 
            if (tableFeatBenefit.Rows.Count == 0)
            {
                row = new TableRow();
                cell = new TableCell();
                cell.ID = "FeatureHR";
                cell.Text = "Feature";
                row.Cells.Add(cell);
                cell = new TableCell();
                cell.ID = "BeneitHR";
                cell.Text = "Benefit";
                row.Cells.Add(cell);
                this.tableFeatBenefit.Rows.Add(row);
            }
 
            const int colsCount = 2;
 
            // Now iterate through the table and add your controls
 
            for (int i = tableFeatBenefit.Rows.Count; i < numOfRows+1; i++)
            {
                row = new TableRow();
 
                for (int j = 0; j < colsCount; j++)
                {
                    cell = new TableCell();
                    TextBox tb = new TextBox();
 
                    tb.ID = "FeatBenTextBoxRow_" + i + "Col_" + j;
                    cell.Controls.Add(tb);
                    row.Cells.Add(cell);
                }
 
 
                this.tableFeatBenefit.Rows.Add(row);
            }
 
            //Set Previous Data on PostBacks
            SetPreviousData(numOfRows, colsCount);
 
            tableFeatBenefit.DataBind();
            
        }
 
 
        private void SetPreviousData(int rowsCount, int colsCount)
        {
            if (tableFeatBenefit != null)
            {
                for (int i = 1; i < rowsCount+1; i++)
                {
 
                    TextBox feature = (TextBox)tableFeatBenefit.Rows[i].Cells[0].FindControl("FeatBenTextBoxRow_" + i + "Col_0");
                    
                    var temp = (from string a in tableFeatBenefit.Page.Request.Form.AllKeys
                                where a.EndsWith("FeatBenTextBoxRow_" + i + "Col_0")
                                select a).FirstOrDefault();
 
                    if (temp!=null)
                        feature.Text = tableFeatBenefit.Page.Request.Form[temp];
 
                    TextBox benefit = (TextBox)tableFeatBenefit.Rows[i].Cells[1].FindControl("FeatBenTextBoxRow_" + i + "Col_1");
                    
                    temp = (from string a in tableFeatBenefit.Page.Request.Form.AllKeys
                            where a.EndsWith("FeatBenTextBoxRow_" + i + "Col_1")
                            select a).FirstOrDefault();
 
                    if (temp != null)
                        benefit.Text = tableFeatBenefit.Page.Request.Form[temp];
                }
            }
        }
        #endregion
    }
}
 
 
 

FeatureBenefitTemplateRender.ascx

Show/Hidden html5 code

View source
 
 
 
<%@ 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="FeatureBenefitTemplateRender.ascx.cs" Inherits="LucaCostante.SP.CF.CONTROLTEMPLATES.FeatureBenefitTemplateRender" %>
 
<SharePoint:RenderingTemplate ID="FeatureBenefitTemplate" runat="server">
    <Template>
        <asp:UpdatePanel ID="up_Table" runat="server">
            <ContentTemplate>
                <asp:table id="tbl_FeatureBenefit" runat="server"></asp:table>
                <asp:Button ID="btn_Add" runat="server" Text="+" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </Template>
</SharePoint:RenderingTemplate>
 
<SharePoint:RenderingTemplate ID="FeatureBenefitTemplateForDisplay" runat="server">
  <Template>
    <asp:Table ID="tbl_FeatureBenefitForDisplay" runat="server" />
  </Template>
</SharePoint:RenderingTemplate>
 
 
 

Tuesday, 26 February 2013 16:35

Use a non default webfont

Some customers when ask us to develope the Intranet or other SharePoint sites, they want to use another font otherwise default fonts.

All websites can use the WebFonts (at this link, you can find all web fonts and can download it). To use a non-default webfont also under SharePoint , you must deploy it into your farm (in my example, i've added it under layouts mapped folder).

After that, must add into the css file the directive:

Show/Hidden css code

View source
 
 
 
@font-face {
    font-family: 'OpenSans';
    src: url('/_layouts/style/fonts/OpenSans-CondLight-webfont.eot');
    src: url('/_layouts/style/fonts/OpenSans-CondLight-webfont.eot?#iefix') format('embedded-opentype'),
         url('/_layouts/style/fonts/OpenSans-CondLight-webfont.woff') format('woff'),
         url('/_layouts/style/fonts/OpenSans-CondLight-webfont.ttf') format('truetype'),
         url('/_layouts/style/fonts/OpenSans-CondLight-webfont.svg#OpenSansCondensedLight') format('svg');
    font-weight: normal;
    font-style: normal;
}
 
 
 

 

In this example, I wanto to explain how to use the Client Object Model to retrieve User Profile Properties.

In my example, I have a list with some fields and one of this is a SPFieldUserValue (UserField is the internal name of my field).

Show/Hidden csharp code

View source
 
 
 
ClientContext clientContext = new ClientContext("htttp://intranet.domain022.dev");
clientContext.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
 
 
Site siteCol = clientContext.Site;
Microsoft.SharePoint.Client.Web web = clientContext.Web;
clientContext.Load(web, w => w.Title, w => w.Language, w => w.ServerRelativeUrl);
clientContext.ExecuteQuery();
 
 
clientContext.Load(web, c => c.Lists);
clientContext.ExecuteQuery();
 
List list = web.Lists.GetByTitle("CustomList");
clientContext.Load(list);
clientContext.ExecuteQuery();
 
 
var userInfoList = clientContext.Web.SiteUserInfoList;
clientContext.Load(userInfoList);
 
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View/>";
Microsoft.SharePoint.Client.ListItemCollection items = list.GetItems(camlQuery);
clientContext.Load(items);
clientContext.ExecuteQuery();
 
foreach (Microsoft.SharePoint.Client.ListItem item in items)
{
    clientContext.Load(item);
    clientContext.ExecuteQuery();
    
    var temp = item["UserField"];
    
    var query = new CamlQuery { ViewXml = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='ID' /><Value Type='int'>" + ((FieldUserValue)temp).LookupId + "</Value></Eq></Where></Query></View>" };
    var user = userInfoList.GetItems(query);
    clientContext.Load(user);
    clientContext.ExecuteQuery();
    if (user.Count > 0)
    {
 
 
        //here I retrieve only Name property. You can iterate on all properties to view all User properties
        string name = user[0].FieldValues["Name"] as string;
        Console.WriteLine(string.Format("User found {0} with id {1}", name.Split('|').LastOrDefault(), user[0].Id));
    }
    else
    {
        Console.WriteLine(string.Format("User not found: {0} with id {1}", ((FieldUserValue)temp).LookupValue;, ((FieldUserValue)temp).LookupId.ToString()));
    }
}
 
 
 

Hi all, here I want describe two function that use the SharePoint Client Object Model:

  1. to download a file from a SharePoint website to a local path;
  2. to upload a file from a local path to a SharePoint website.

Show/Hidden csharp code

View source
 
 
 
public static bool DownloadFile(ClientContext context, string fileRelativeUrl, string destinationPath, string fileName)
{
    try
    {
        fileRelativeUrl = fileRelativeUrl.Replace("/Images/","/PublishingImages/");
        string sourceUrl = fileRelativeUrl + fileName;
        string completeDestinationPath=destinationPath  + fileName;
        
        if (!System.IO.File.Exists(completeDestinationPath))
        {
            Directory.CreateDirectory(destinationPath);
            FileInformation spFileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, sourceUrl);
 
            using (Stream destination = System.IO.File.Create(completeDestinationPath))
            {
                for (int a = spFileInfo.Stream.ReadByte(); a != -1; a = spFileInfo.Stream.ReadByte())
                    destination.WriteByte((byte)a);
            }
        }
    }
    catch (Exception ex)
    {
        Logger.WriteLog(string.Format("Error during copying file: {0} with error {1}", fileRelativeUrl, ex.StackTrace));
        return false;
    }
    return true;
}
 
 
 
 
 
public static void UploadFile(Web currWeb, string destRelativeUrl, string file, ClientContext destContext)
{
    try
    {
        Microsoft.SharePoint.Client.File destFile = currWeb.GetFileByServerRelativeUrl(destRelativeUrl);
        bool bExists = false;
        try
        {
            destContext.Load(destFile);
            destContext.ExecuteQuery(); //Raises exception if the file doesn't exist
            bExists = destFile.Exists;  //may not be needed - here for good measure
            Logger.WriteLog(string.Format("File already exist: {0}", destRelativeUrl));
        }
        catch
        {
        }
 
        if (!bExists)
        {
            using (FileStream fs = new FileStream(file, FileMode.Open))
            {
                Microsoft.SharePoint.Client.File.SaveBinaryDirect(destContext, destRelativeUrl, fs, false);
                Logger.WriteLog(string.Format("File copied: {0}", destRelativeUrl));
            }
        }
    }
    catch (Exception ex)
    {
        Logger.WriteLog(string.Format("Error during upload file: {0} with error {1}", file, ex));
    }
}
 
 
 

Here a wiki to help to use the SharePoint Client Object Model.

The function above show how to change programmatically the PageLayout (and the associated ContentType) to a PublishingPage.

Show/Hidden csharp code

View source
 
 
 
private static void ModifyPageLayout(string siteUrl, string pageName, string pageLayoutName)
{
    using (SPSite site = new SPSite(siteUrl))
    {
        using (SPWeb myWeb = site.OpenWeb())
        {
            PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(myWeb);
            
            PublishingPage page = publishingWeb.GetPublishingPage(siteUrl + "/pages/" + name);
            if (!string.IsNullOrEmpty(templateName) && page!=null)
            {
                PageLayout pl = page.PublishingWeb.GetAvailablePageLayouts().Where(p => string.Compare(p.Name, pageLayoutName, true) == 0).FirstOrDefault();
                if (pl != null)
                {
                    page.CheckOut();
                    page.Layout = pl;
                    
                    // Now set the content type
                    page.ListItem[SPBuiltInFieldId.ContentTypeId] = pl.AssociatedContentType.Id;
                    page.ListItem[SPBuiltInFieldId.ContentType] = pl.AssociatedContentType.Name;
 
                    page.Update();
                }
            }
        }
    }
}
 
 
 

Tuesday, 22 January 2013 16:20

SharePoint 2013 very slow

After SharePoint 2013 installation ad configuration with wizard, it results very slow to load pages.

After some checks, the problem is that the search service is started and need a lot of resources and if it is not used yet, it can be stopped.

Login into the SharePoint central administration, navigate to "Application Management" -> "Manage services on server" and stop this services (as into the below image):

  • Search Host Controller Service
  • Search Query and Site Settings Service

SharePoint 2013 search

After this, open Windows Services and disable this services (as into the below image):

  • SharePoint Search Host Controller
  • SharePoint Server Search 15

 Windows services

 Now the Machine is as fast as a dragonfly ;)

At work, I've develop an User Control that add a ListFormWebPart for adding answers to a Survery List into a publishing page.

In page view, the webpart was rendered correctly and when I click on Add button (to answer the survey), all went well except that the list item that was addes has empty values o.O

{codecitation}

ListFormWebPart lfw = new ListFormWebPart();
lfw.ID = "SurveyWP";
lfw.Title = "";
lfw.ListId = survey.ID;
lfw.ListItemId = 0;
lfw.PageType = PAGETYPE.PAGE_NEWFORM;
lfw.ViewFlags = SPViewFlags.Default;

 

this.Page.Controls.AddAt(lfw,2);

{/codecitation}

The error is that to add the WebPart into the page, I've used at 9th line the AddAt method to add the WebPart at 2nd position.

Using this method to add the WebPart into the page, the system loses the values specified by the users.

The workaround is to use Add method instead AddAt method ad use a div to add the WebPart into a specified position in the page.

{codecitation}

this.containerDiv.Controls.Add(lfw);

{/codecitation}

 

Some days ago, with a my friend we are talk about a problem that have encourred at work. An user have created a publishing page and have asked him to help her to modify and publish it. When my friend went on pages list, he didn't find the desired page.

So the user that have created the page, can view it into Page list; other users don't see it into Page list.

After some search, we found the solution. When a page was created and until it's check-in, this pages is stored into an hidden list. To access to this list, the user must navigato to:

Pages List -> Library tab -> Library settings -> “Manage files which have no checked in version” (see the below picture)

A small bit of text above the list explains the reason:  “Use this list to manage files which have no checked in version”.

 

Page 4 of 5