Tuesday 30 April 2013

Calendar not showing on Sharepoint 2010

Sorry to post this in my blog (it is too newbie) , but I keep forgetting the name of the feature activates the calendar. Well, if you notice there is not a calendar in your list, it is probably because the “Group Work List” feature is not activate it. To do it, just follow these steps:

Step 1
Go to Site Actions –> Site Settings –> Site Actions –> Manage site features

Step 2
Activate the feature “Group Work List” (see the image below)
image

Step 3
Activate “Team Collaboration Lists” (see image below)
image

Thursday 25 April 2013

Adding a hidden field to a Sharepoint 2010/2013 list.

Today I am celebrating 100,000 visits of my blog with this beautiful post.

The other day was trying to add some columns to a Survey list, and I noticed that every column was a particular question of the survey. I only want to keep extra data in the list without displaying it, so I add what it is called in Sharepoint a hidden field. A hidden field it is considered a system field for Sharepoint, something the user can’t see. The is a good way to find hidden fields, just open the list on Sharepoint Designer 2010 and you will be able to see them.

This code will allow you to add a hidden field called “myhiddencolumn”

using (SPSite _site = new SPSite(SPContext.Current.Web.Url))
{
  using (SPWeb _web = _site.OpenWeb())
  {
     String _sField= "<Field Hidden=\"TRUE\" Type=\"Text\" DisplayName=\"myhiddencolumn\" ResultType=\"Text\" ReadOnly=\"False\" Name=\"myhiddencolumn\"> </Field>";
     _web.AllowUnsafeUpdates = true;
     SPList _spList = _web.Lists["mysurveylist"];
     _spList.Fields.AddFieldAsXml(_sField);
     _spList.Update();
   }
}

Thursday 18 April 2013

Caml Builder 4.0.0.0 / Camlbuilder 4.0.0.0 download for Sharepoint 2007 / 2010 / 2013 & Caml Designer 2010

Caml Builder 4.0.0.0
I have notice the beautiful page u2u.be doen’t seem to provide this software to query Sharepoint 2007 and Sharepoint 2010 lists. The whole tool is a piece or art, because allows you to create CAML queries plus the real content of a particular list.
Because I keep the latest copy of this software, I decided to share it with, until u2u.be decide (if they do) re-detribute this tool again.
Click here to download CamlBuilderSetupv4.0.0.0.zip
Caml Designer 2010
This tool is new in the market, and it is a wrapper of the famous CAML Builder, It has better functionality an a better user interface.
Click here to download CamlDesigner.zip
Oficial website: http://www.biwug.be/
Enjoy!

Wednesday 17 April 2013

Survey questions are not exported in the right order when you select “export to spreadsheet” to Excel on Sharepoint 2010.

Surveys in Sharepoint 2010 are quite limited, but I have to admit this limitation brings simplicity to the users. Some users become quite confuse when it comes to InfoPath, so why not giving them the option of developing surveys?.

If one of them it is causing trouble and needs extra functionality, we can always add it, at the end of the day a Survey is a custom list.

There is bug in Sharepoint 2010 where the survey questions are not exported in the right order when you select “export to spreadsheet”. Why is this happening?, because a file called Overview.aspx as well as AllItems.aspx and summary.aspx have been build gradually in LILO (Last In Last Out) order. To fix this issue we only need to edit these files, and I will advise to modify only Overview.aspx. This file has the option to “export to spreadsheet”.

Step 1
Click on your survey, and you will end in a screen like this:
image

 

Step 2
Copy the URL without “/overview.aspx” and open Sharepoint Designer, go to “Open Site” and click to open.
image

 

Step 3
Go to “Lists and Libraries” and select “mysurvey” (this is my survey, select yours). Select “Overview” on the right side and double click.
image

The page will be opened, select “Code” (bottom), to see the code of the page.
image

 

Step 4
Go to the section it says <ViewFields> and choose the order you want. The order of these fields will be the order of the output of your spreadsheet. You can add extra fields if you want.

<XmlDefinition>
	<View Name="{E82854CC-2572-4FD2-A2B1-4BD74EE111D6}" DefaultView="TRUE" Type="HTML" TabularView="FALSE" ReadOnly="TRUE" FreeForm="TRUE" DisplayName="Overview" Url="/extranetpresentation/Lists/mysurvey/overview.aspx" Level="1" BaseViewID="3" ContentTypeID="0x" ImageUrl="/_layouts/images/survey.png" CssStyleSheet="survey.css">
		<ViewFields>
			<FieldRef Name="Author"/>
			<FieldRef Name="my_x0020_0_x0020_question"/>
			<FieldRef Name="_x0031__x0020_My_x0020_first_x00"/>
			<FieldRef Name="my_x0020_second_x0020_qestion"/>
			<FieldRef Name="my_x0020_third_x0020_question"/>
			<FieldRef Name="Type_x0020_your_x0020_question_x"/>
		</ViewFields>
		<Toolbar Type="Standard"/>
	</View>
</XmlDefinition>


 


Conclusion: All Responses, Graphical Summary and Overview are the files which control the out of the box survey. We just need to access to these files to customise our “out of the box” surveys.

Friday 12 April 2013

Getting the First or Last element of a list in Sharepoint 2013 (2010 compatible) using the object model.

This is one of the missing commands in Sharepoint, get the first and the last element of a list really quickly. There is a way, of doing it with LINQ, but the performance is ridiculous, you don’t really want to go for the LINQ route.

What are the alternatives for this issue? well, we all know CAML is the fastest way, outside SQL to get data from Sharepoint, so let’s go to do it like this.

To get the last element of the list (in this case Title):

SPQuery query = new SPQuery();
query.RowLimit = 1;
query.Query = "<OrderBy><FieldRef Name='ID' Ascending='FALSE' /></OrderBy>";
SPListItemCollection listItemCollection = _spList.GetItems(query);
//## GETTING THE LAST ITEM TO GET THE ID
if (listItemCollection.Count > 0)
{
      if (listItemCollection[0]["Title"] != null)
      {
             _iTitle = Convert.ToInt32(listItemCollection[0]["Title"]);
             _iTitle++;
      }                            
}

To get the first element of the list (in this case Title):
SPQuery query = new SPQuery();
query.RowLimit = 1;
query.Query = "<OrderBy><FieldRef Name='ID' /></OrderBy>";
SPListItemCollection listItemCollection = _spList.GetItems(query);
//## GETTING THE LAST ITEM TO GET THE ID
if (listItemCollection.Count > 0)
{
    if (listItemCollection[0]["Title"] != null)
    {
        _iTitle = Convert.ToInt32(listItemCollection[0]["Title"]);
        _iTitle++;
    }                            
}

Conclusion: CAML still the fastest way to do queries in Sharepoint, just use your imagination and go for it!

Tuesday 9 April 2013

How to reduce Sharepoint Config Log file size in Sharepoint 2010/2013

You have probably notice that after a while you space in the disk has grown when you have not done anything especial with Sharepoint. This issue is normally caused by logs. They log all the time, so even if the server is idle they have to report something.

Follow these steps to reduce the log in the Sharepoint Config database.

Step 1
Find out where you “Sharepoint_Config” Database is.

Step 2
Open the SQL 2008/2012 Server Manager Studio with the name of the server where the DB is kept.

Step 3
Select the DB, right click and open New Query:
image

Step 4
Thinking we are going to keep a backup in our R drive (change the drive depending of what you use C perhaps?), type the following and press “F5”:

BACKUP LOG [Sharepoint_Config] TO DISK='r:\configLogBackup.bak'
Step 5
Go to the DB itself, right click and go to properties. Under properties select options and recovery model, and then select simple:


Step 6
Now let’s go to Shrink the Sharepoint_Config log to 50 MB, just type the following SQL Command:

DBCC SHRINKFILE('Sharepoint_Config_Log',50)


Step 7
Once this is done we come came back to DB , right click and go to properties. Under properties select options and recovery model, and then select Full:

Setting default data in a List Definition on Sharepoint 2013

This is a handy trick. When you create a list definition, sometimes you want to set default values, as easy as using the element <Default> and insert the default data between <Default> (ie: <Default>#FFEBCD</Default> ).

Have a look to this example coming from my Schema.xml:

<Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B99}" Name="alphatop" DisplayName="alphatop" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE">
 <Default>1.0</Default>
</Field>
<Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B00}" Name="alphabottom" DisplayName="alphabottom" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE">
 <Default>1.0</Default>
</Field>
<Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B01}" Name="overlayimagebottomenabled" DisplayName="overlayimagebottomenabled" Type="Boolean"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>      
<Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B02}" Name="overlaycolorbottom" DisplayName="overlaycolorbottom" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
<Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B03}" Name="bordercolor" DisplayName="bordercolor" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE">
 <Default>#FFEBCD</Default>
</Field>      
I have introduced “#FFEBCD” as default value for the border color, I have also set the “alphabottom” value to 1.0.


A attach a full copy of a working lint definition:

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="PresentationLI" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/PresentationLI" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>    
    <Fields>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B81}" Name="topstartx" DisplayName="topstartx" Type="Integer" Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>                
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B82}" Name="topstarty" DisplayName="topstarty" Type="Integer" Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B83}" Name="topendx" DisplayName="topendx" Type="Integer" Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE" />       
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B84}" Name="topendy" DisplayName="topendy" Type="Integer"  Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B85}" Name="middlestartx" DisplayName="middlestartx" Type="Integer"  Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B86}" Name="middlestarty" DisplayName="middlestarty" Type="Integer"  Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B87}" Name="middleendx" DisplayName="middleendx" Type="Integer"  Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B88}" Name="middleendy" DisplayName="middleendy" Type="Integer"  Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B89}" Name="offsetx" DisplayName="offsetx" Type="Integer"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B90}" Name="offsety" DisplayName="offsety" Type="Integer"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B91}" Name="name" DisplayName="name" Type="Text"  Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B92}" Name="description" DisplayName="description" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B93}" Name="version" DisplayName="version" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B94}" Name="releasedate" DisplayName="releasedate" Type ="DateTime"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B95}" Name="audience" DisplayName="audience" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B96}" Name="features" DisplayName="features" Type="Note"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B97}" Name="overlayimagetop" DisplayName="overlayimagetop" Type="URL"  Required="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B98}" Name="overlayimagebottom" DisplayName="overlayimagebottom" Type="URL"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B99}" Name="alphatop" DisplayName="alphatop" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE">
        <Default>1.0</Default>
      </Field>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B00}" Name="alphabottom" DisplayName="alphabottom" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE">
        <Default>1.0</Default>
      </Field>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B01}" Name="overlayimagebottomenabled" DisplayName="overlayimagebottomenabled" Type="Boolean"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>      
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B02}" Name="overlaycolorbottom" DisplayName="overlaycolorbottom" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE"/>
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B03}" Name="bordercolor" DisplayName="bordercolor" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE">
        <Default>#FFEBCD</Default>
      </Field>      
      <Field ID="{24B3F6C1-B75B-4821-A466-C1E979B87B04}" Name="borderwidth" DisplayName="borderwidth" Type="Text"  Required="FALSE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE">
        <Default>5px</Default>
      </Field>
    </Fields>
    <Views>
      <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">main.xsl</XslLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <FieldRef Name="LinkTitleNoMenu"></FieldRef>
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="Modified" Ascending="FALSE"></FieldRef>
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
        </ParameterBindings>
      </View>
      <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">main.xsl</XslLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <FieldRef Name="Attachments"></FieldRef>
          <FieldRef Name="LinkTitle"></FieldRef>
          
          <FieldRef Name="topstartx"> </FieldRef>
          <FieldRef Name="topstarty"></FieldRef>
          <FieldRef Name="topendx"></FieldRef>
          <FieldRef Name="topendy"></FieldRef>
          
          <FieldRef Name="middlestartx"></FieldRef>
          <FieldRef Name="middlestarty"></FieldRef>
          <FieldRef Name="middleendx"></FieldRef>
          <FieldRef Name="middleendy"></FieldRef>
          <FieldRef Name="offsetx"></FieldRef>
          <FieldRef Name="offsety"></FieldRef>
          
          <FieldRef Name="name"></FieldRef>
          <FieldRef Name="description"></FieldRef>
          <FieldRef Name="version"></FieldRef>
          <FieldRef Name="releasedate"></FieldRef>
          <FieldRef Name="audience"></FieldRef>
          <FieldRef Name="features"></FieldRef>
          <FieldRef Name="overlayimagetop"></FieldRef>
          <FieldRef Name="overlayimagebottom"></FieldRef>
          <FieldRef Name="overlayimagebottomenabled"></FieldRef>
          <FieldRef Name="overlaycolorbottom"></FieldRef>
          <FieldRef Name="alphatop"></FieldRef>
          <FieldRef Name="alphabottom"></FieldRef>
          <FieldRef Name="bordercolor"></FieldRef>
          <FieldRef Name="borderwidth"></FieldRef>
          </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="ID"></FieldRef>
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
        </ParameterBindings>
      </View>
    </Views>
    <Forms>
      <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
    </Forms>
  </MetaData>
</List>

Tuesday 2 April 2013

Avoiding deleting the data in a list every time you deploy a List Definition on Visual Studio for Sharepoint 2010 and 2013

If you have to work hard to create a big custom list with a List Definition, it will be handy for you to keep the data of that list, instead of being deleted every time you deploy your solution. To do that just do the following:

Step 1
Under the List Definition, select “elements.xml” and open it.
image

Step 2
Add the following attribute (  AllowDeletion="FALSE" ) to your list template. Your List Template should look something like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. -->
    <ListTemplate
        Name="PresentationLI"
        Type="10000"
        BaseType="0"
        OnQuickLaunch="TRUE"
        SecurityBits="11"
        Sequence="410"
        AllowDeletion="FALSE"
        DisplayName="PresentationLI"
        Description="List Definition for DWF Demos"
        Image="/_layouts/images/itgen.png"/>
  
</Elements>


Step 3
Now go to Schema.xml and add the following attribute under <extensiondata>:
image
It should look something like this:

<?xml version="1.0" encoding="utf-8"?>
<ProjectItem Type="Microsoft.VisualStudio.SharePoint.VisualWebPart" DefaultFile="ExtranetUserControl.ascx" SupportedTrustLevels="FullTrust" SupportedDeploymentScopes="Site" xmlns="http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel">
  <Files>
    <ProjectItemFile Source="Elements.xml" Target="Extranet\" Type="ElementManifest" />
    <ProjectItemFile Source="Extranet.webpart" Target="Extranet\" Type="ElementFile" />
    <ProjectItemFile Source="ExtranetUserControl.ascx" Target="CONTROLTEMPLATES\ExtranetPresentation\Extranet\" Type="TemplateFile" />
  </Files>
  <SafeControls>
    <SafeControl Name="SafeControlEntry1" Assembly="$SharePoint.Project.AssemblyFullName$" Namespace="ExtranetPresentation.Extranet" TypeName="*" IsSafe="true" IsSafeAgainstScript="false" />
  </SafeControls>
  <ExtensionData>
    <ExtensionDataItem Key="DeploymentConflictResolutionBehavior" Value="None" />
  </ExtensionData>
</ProjectItem>