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

Friday, 21 February 2014

How to create a search box or filter for a list in the same page allowing you to work in the same page. Applicable for Sharepoint 2010 and Sharepoint 2013

I was asked if I could create a page with one massive list, but with only one filter box. That is not possible to do it with the Filter web part, unless you only want to filter for one parameter. In this case I had 50 columns to filter and more than 10,000 items in the list. So I didn’t want to have 50 text boxes all over the page.

I decided to use the designer to create a Query string where I can pass my 50 parameters and then filter all of them with an OR clause. The best tool to do this it is the designer. For the User interface I use the HTML webpart and few lines of Javascript code.

For this excersise I am going to use Sharepoint 2010 and Microsoft SharePoint Designer 2010 BUT you can do exactly the same with Sharepoint 2013 and Microsoft SharePoint Designer 2013.

Step 1 - Create the place holder page
Go to Microsoft SharePoint Designer 2010->Open your site->Site pages->Right click on the left side->New->ASPX Page
image

I called the page Search.aspx.

Step 2 – Set the Masterpage for the page
Click on the page you have just created-> Edit file
image

Click on Design (Bottom)
image

Click on Style(top Ribbon)->Attach->Default Master Page. You should have a normal page now. I have selected my custom Master Page, so mine will look different than the Out-Of-The-Box one. Select the main place holder and click in the little arrow, a new menu will pop-up-> Click on Create Custom Content. Click on Save.
image

Step 3 – Adding the list and the code behind
Click on Main the main place holder
image

Insert->DataView->Select the List you want and you should have something like this:
image

Click on Code (bottom of the designer) and paste this code just below the PlaceHolderMain this line:

<WebPartPages:SimpleFormWebPart webpart="true" runat="server" __WebPartId="{29221221-845B-4910-B7DC-B6898D38966F}"><WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
	<Description>Connects simple form controls to other Web Parts.</Description>
	<PartImageLarge>/_layouts/images/mssfwp.gif</PartImageLarge>
	<sfwp:Content xmlns:sfwp="http://schemas.microsoft.com/WebPart/v2/SimpleForm"><![CDATA[<style type="text/css"> 
  		body #s4-leftpanel { display: none; } 
  		.s4-ca { margin-left: 0px; } 
	</style>
	<script>	
		function Search()
		{ 	
		  searchtext = document.getElementById('searchTxt').value;		  
		  window.location.href = document.URL.split("?")[0] + '?value=' + searchtext;
		}		
		</script>
		<div onkeydown="javascript:if (event.keyCode == 13) Search()">
			<input type="text" name="T1" id="searchTxt" size="50"/>&nbsp;&nbsp;
			<input type="button" value="&nbsp;&nbsp;Search°&nbsp;&nbsp;" onclick="Search()"/>
		</div>
		<br>
		]]></sfwp:Content>
	<ID>g_29221221_845b_4910_b7dc_b6898d38966f</ID>
<FrameType>None</FrameType>
</WebPart></WebPartPages:SimpleFormWebPart>
The code should look like this:
image
This code is just a HTML Form Web Part with some Javascript and HTML code inside. You can just insert the web part from the designer and add the code from the web part.


Step 4 – Adding the parameters
Click on the list-> Top Ribbon –> Options –> Parameters.
image


Click on New Parameter->add one called “searchparam” Select Parameter Source=Query String and Query String Variable=value.
image


Step 4 – Adding the filter
Now it is time to add the fields you want to filter. Click on the list Go to the Ribbon and click on Filter, a new dialog will pop up, you can do your own search over there.
image



Click on save and go to your page, remember it is under SitePages. Notice the query string changes every time you insert a value in the text box. By the way, the list will look empty until you type a value.
image


Enjoy!

Thursday, 3 October 2013

Hiding the “Save and Close” button in Sharepoint 2010 and Sharepoint 2013


To hide the “Save and Close” button:

  1. Go to your designer
  2. On the left side click on “All Files”
    image
  3. Go to lists –> Select your survey-> And click on it.
  4. You will have the following pages (we only need to update two)
    image
  5. Right Click on NewForm.aspx->Open With->Sharepoint Designer(Open as text)
  6. Find the following line (section) : <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
  7. Copy this code below:
    <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script>   
    $(document).ready(function () {
        $(":input").each(function () {                                   
    	var _sInputValue = $(this).val();                                        
    	if (_sInputValue==="Save and Close") $(this).hide();
        });
    });
    </script>

  8. Go to you NewForm.aspx on the designer, right click and “Check Out” and then “Check In”

  9. Do the same with EditForm.aspx

Monday, 5 August 2013

Verify that the service account has permissions to the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Forefront Identity Manager\2010\Synchronization Service on Sharepoint 2010 & Sharepoint 2013

This has been one of my nightmares for days. This is one of the error messages (Verify that the service account has permissions to the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Forefront Identity Manager\2010\Synchronization Service) which I managed to fix, how?:

In order to make the User Profile Synchronization Service to work, it has taken me few days, the first thing you need to make sure, if you are working with a farm, it is you are working in the same machine where you are going to activate the service. In order to do that go to Central Administration->Manage Services on Server and select your server (yes! the one you are working on)
image

Then stop and start User Profile Synchronization Service and WAIT! yes! wait for 5 minutes it takes a while. Now start User Profile Service.

image

Ok we have both successfully started. Now it is time to see if our services, which will be running with our admin service account, starts. So go to “Services” on your server and check if Forefront Identity Manager Service and Forefront Identity Manager Synchronization Service have started, if not start first, Forefront Identity Manager Synchronization Service  and Forefront Identity Manager Service after:
image

If you still getting the same message, you will probably give rights to that particular key for your account.

Thursday, 2 May 2013

Where to find the saved template on Sharepoint 2010 & Sharepoint 2013

This is an easy one, but very handy when you have saved one List Template from a list and you can’t find it.

image

Sharepoint leaves all the list templates under:

/_catalogs/lt/Forms/AllItems.aspx


“lt” in the URL means List Template. To access, just type the name of your site plus the line before, ie: http://sp2010dev/_catalogs/lt/Forms/AllItems.aspx .

Of course you can always access with the marvellous Site Action->Site Settings.

image

Enjoy!

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!

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>