Some thoughts on programming stuff

Tag: SharePoint (Page 4 of 4)

Repair Lookup column in SharePoint

Sometimes it’s necessary to repair Lookup column in SharePoint. Usually it can happen when we need to transport a list from a Production environment to a Development environment, just to reproduce some bug or situation with real world data. This is possible when you use the Save as Template feature, exporting it from an environment to another and then you recreate the list.

But, if you have Lookup fields it can give you some headaches. As soon as the list is restored in the other environment, the Internal GUIDs will be changed forever and any connection to the source list of the lookup column will be lost!

But it’s important to emphasize that Lookup columns are great as Microsoft says that “You can create relationships between lists by using a combination of unique columns, lookup columns, and relationship enforcement (cascade and restrict delete), all of which enhance your ability to create more sophisticated business solutions and help preserve the integrity of your data.”.

Continue reading

SPQuery best practices in SharePoint

This post will cover SPQuery best practices in SharePoint due to my recent experience with customers complaining about the performance of their SharePoint sites. This problem collaborated to create a bad impression of the product. “The page takes too long to load” or “Web Parts with pagination are terrible” were some of their complaints.

After the first contact with them, I usually asked for the source code to find out what was happening and do some troubleshooting. It didn’t take too much to find out that almost every case had performance issues due to queries being made with the SPList.Items property and followed by some LINQ query to filter the data.

Continue reading

Copy and paste images in SharePoint

This blog post covers a customized script that can be applied to SharePoint sites, letting you be able to copy and paste images in SharePoint. The content is focused on developers, because the installation process may not be so easy to be executed.

Copying and pasting images is a common customer demand to make their lifes easier when working with SharePoint pages and publishing new content. Although my automatic answer has been always “Just upload it through the ribbon, so you can add metadata and ensure content quality and reusability“, I must admit that this way isn’t THAT user-friendly.

That’s why I decided to develop some JavaScript code to add this functionality to my Web Pages. So the users would be able to add their images faster. Basically, I’ve created a GitHub repository to keep the code, so maybe someone can help me on refactoring it or adding support for others browsers.

The project to enable copy and paste images

Github project: https://github.com/wiliammbr/sp-copypasteimages

The project is a SharePoint provider-hosted app that publishes some JavaScript files to your Site Assets library. It was developed based on some SharePoint projects in the PnP – Patterns and Practices repository. Microsoft and the community maintains the repository updated. Also, it will add ScriptLinks to insert those script files into your pages. In my example, the app was hosted in an Azure Cloud Service.

But if your prefer, it’s possible to add those scripts into your Master Page files too, so you don’t need the Provider-hosted App approach.

Continue reading

You are not allowed to respond again to this survey in SharePoint

One of my favorite list templates in SharePoint is the Survey template. It’s a fun and useful feature that helps you on achieving good survey-like forms with charts and insights. You can make them anonymous, do some customizations and add Branching Logic, which means conditional questions depending on what the user answers. But unfortunatelly there are some drawbacks like the message you receive of You are not allowed to respond again to this survey in SharePoint.

You are not allowed to respond again to this survey in SharePoint - Form example
Form example
You are not allowed to respond again to this survey in SharePoint - Survey overview
Survey overview

But it has one main behaviour that I just don’t like, that is the message when you try to answer the survey again. Below you can check the message with Custom Errors disabled.

You are not allowed to respond again to this survey in SharePoint - Error message
Error message

Theorically, the user has the required permission to edit its answers. But unfortunatelly once I try to answer again, SharePoint shows me that message as an error. This is a huge problem for users that don’t understand this message and it can be negative to the system.

Continue reading

List operations with CSOM and C# in SharePoint

Sometimes we have to query a SharePoint list through remote connections using C#. It can happen in a SharePoint App, a Console Application or maybe on an Azure Function. This post will help on performing list operations with CSOM and C# in SharePoint.

Below you can find some code snippets that will help you on integrating SharePoint lists with your application.

Basically, you will have to add the Microsoft.SharePoint.Client namespace.

using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

The required DLLs for programming these type of solution are:

Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll

You can find them inside those folders:

SharePoint 2010: 14 Hive -> Folder: ISAPI

SharePoint 2013: 15 Hive -> Folder: ISAPI

Or just download it from MSDN, inside the SharePoint Server 2013 Client Components SDK!

After adding these references to our project, we can start coding and accessing the data in the SharePoint List you want!

A custom list creation screen

Soon you will notice that everything depends on the ClientContext object, which manages the requests and the data that will be loaded.

In our examples we are going to use the variable siteUrl, that represents the URL for the Site Collection. The variable listTitle will also be used and it represents the Title of the list being used.

string siteUrl = "http://sitesharepoint";
string listTitle = "SharePointList";

So, let’s do some real stuff here:

Read operation in SharePoint lists

Filtering and selecting specific fields

The example below presents a simple code that queries only one list item from the List and specifies some specific columns to be returned. It’s important to say that exists lots of best practices to build good queries in SharePoint.

Creation operation in SharePoint lists

 Update operation in SharePoint lists

 Delete operation in SharePoint lists

I believe these are the basics for consuming SharePoint lists. In the future I’m planning to show some complex examples, more focused on Office 365 and Azure integrations. Thanks for reading and I hope it can be useful to you when you need to perform list operations with CSOM and C# in SharePoint.

References:
MSDN

Study Guide for Exam 70-488 – Developing Microsoft SharePoint Server 2013 Core Solutions

Since last year, we received the announcement that some of the SharePoint 2013 certifications were being retired in September of last year. But after that, they extended the deadline to 2017. This new deadline can be explained due there is no new certifications focused on development for SharePoint 2016 have been released yet.

Exam on Microsoft’s website: https://www.microsoft.com/pt-br/learning/exam-70-488.aspx

Therefore, here is a set of links that you can use as a study guide to pass on that exam before it is retired.
This summary was once made by Martin Bodocky and kept on this blog post “70-488 – Developing Microsoft Sharepoint Server 2013 Core Solutions – Preparation links“. Unfortunatelly, it’s not online anymore, so I decided to provide this information once again at the same time that I must say: Bodocky made everything and helped me on passing this exam, back on 2014.

If you want to read the preparation links for the Advanced Solutions, please check the post for the test Study Guide for Exam 70-489 – Developing Microsoft SharePoint Server 2013 Advanced Solutions.

Continue reading

Get user info programmatically in SharePoint

Sometimes when we are developing a custom solution, we need to get user info programmatically in SharePoint. It doesn’t matter if you need to show a special message to an specific user using its Personal Name or maybe just fill a SPFieldUser column in a specific list, you’ll probably need one of those code snippets to do the trick.

I’m going to split it into Server-side object model for C# developers, REST API (for SharePoint 2013 projects or newer) and the old-fashioned JavaScript object model introduced in SharePoint 2010. Each one wil let you capture the current user or get an user by its ID or login name. After that it’s up to you what you are going to do with the data.

SharePoint users inside the User Information List (hidden)
Continue reading

Hide Content Query Web Part when empty

For those who want to hide Content Query Web Part when empty, in other words, when it returns not data, this post is for you! The solution won’t require you to dive into XSL world, it’s pure JavaScript. Basically you will drop the code code snippet to your pages and everything will work.

The Content Query Web Part (CQWP) is a great way to query data from other sites and present it inside one page. Content Query Web Part can be used with their default layouts or you can create some if want.

According to a Code Project article: ” This web part is rather nifty and it has many cool features. With the CQWP, you can now control how the content is displayed. We can use html tables to format the display however we wish. This article explains how to customize the CQWP using SharePoint 2010 without any code and deployment. “.

The Content Query Web Part - Hide Content Query Web Part when empty
The Content Query Web Part

Unfortunatelly, this post may be a little bit outdated because Microsoft reinforces that Content Search Web Part is a better option now. You can check this post when to use the Content Query Web Part or the Content Search Web Part in SharePoint.

Continue reading
Newer posts »

© 2024 wiliammbr's blog

Theme by Anders NorenUp ↑