Posts

Showing posts from 2015

How to support multiple languages in WPF

Image
If you are developing many solutions for many costomer, one day one of them will require a multilingual WPF-solution. So there is the question: how to make a WPF form multilingual? At first you need at least two languages that you want to support. You can add some other languages at the end very easy. First of all create a folder in your project and call it "Languages", to keep an overview. Once it is done you can create Resource Dictionaries in this folder. You can call them however you want, but make sure you can assign them to the language. You can use language codes (like "en-us") or you can call it like the language is called. At the end it can look like this:

Get the mail address from a FieldUserValue Client Side vs Server Side

In SharePoint are two ways to code by using an object model. The one way is the Client-Side Object Modell (CSOM) and the other side is the Server-Side Object Model (SSOM). At the first look they both look the same the only difference is how the objects are looking for example the is the 'Site'-object (client side) is called 'SPSite' on server side. A good way to demonstrate the difference is to get the mailaddress of a userfield. That sounds easy, but needs more lines that I thought at first. So let's say you got a SharePoint 2013 and want to read the mailaddress on client side. That would look like this: 1 2 3 4 5 6 7 8 9 // get the userfield of the item e.q. Author FieldUserValue Author = (FieldUserValue)currentItem[ "Author" ]; // ask the web to find a user with the id in the field (only works if the user visited the site) var user = web.SiteUsers.GetById(Author.LookupId); // load the data with the context context.Load(user); context.ExecuteQue

Get data of all users on the SharePoint with CSOM C#

Sometimes you need to get information abot some user. To do so you need the SiteUserInfoList. This list contains data about all user that visited the SharePoint site. This is how you can read the list with C# and CSOM: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // build the SharePoint connection ClientContext clientContext = new ClientContext( "http://your site/" ); Web web = clientContext.Web; // get the userinfolist List siteUserInfoList = web.SiteUserInfoList; // build a query CamlQuery query = new CamlQuery(); query.ViewXml = "" ; // get the data IEnumerable<ListItem> itemColl = clientContext.LoadQuery(siteUserInfoList.GetItems(query)); clientContext.ExecuteQuery(); // work with the userinformations foreach ( var item in itemColl) { Console.WriteLine( "ID:{0} Email:{1} Title:{2}" , item.Id, item[ "EMail" ], item[ "Title" ]); }

SharePoint 2013 apps - communicate with host SharePoint without using SP.RequestExecutor

In a previous post  I wrote an app to read and write data from the Host-SharePoint. To do this I made use of the SP.RequestExecutor. This class is used to get the permissions for reading and writing data into the Host-SharePoint. But there is a way to skip the authentification and using the URL directly. This makes your code much more beautiful and easy to read. All you need to do is to call a function (_spPageContextInfo.siteAbsoluteUrl). That function returns an URL and makes it possible to communicate with the SharePoint per JSOM and REST.  I also tried to call the URL with the function and make a context with another URL and this does not work. Even the Host-URL does not work. Another disgusting point is that the URL, which is returned by the function, is that it not contains the URL of the app and not of the host. It is a 'hybrid' that begins like the app URL, but ends earlier. 1 2 3 4 var url = _spPageContextInfo.siteAbsoluteUrl; context = new SP.ClientContext(ur

Open Edit View of SharePoint Pages without the "Edit Page" button

In some cases the "Edit Page" button is not visible too make sure no one makes some unallowed changes. This is a nice security hack, but what if you need to edit the page? There is an easy way to open the page in edit mode and that is the URL. Add one of the following extensions to your URL, right after the '.aspx'. To change the public view of the page add this: ?PageView=Shared&ToolPaneView=2 example: http://sp/Pages/default.aspx ?PageView=Shared&ToolPaneView=2 To change a personal view of the page add this (only if it is enabled): ?PageView=Personal&ToolPaneView=2 example: http://sp/Pages/default.aspx ?PageView=Personal&ToolPaneView=2

Read an Exchange inbox with WebServices and C#

In some situations you will need to read mails from mailserver. One of those servers is the Exchange. Reading it is pretty easy with the WebServices. At first you need to add the reference to Microsoft.Exchange.WebServices. After that you can begin to code. All you need are two functions. One to build a connection to the Exchange and the other one to find folder and read them.

get SharePoint Farm ID with PowerShell

If you need to get the ID of your SharePoint Farm, you need to use PowerShell. Getting it is easy you just need to enter the following two commands and the ID will appear. $SPFarm = Get-spfarm $SPFarm.ID

SharePoint 2013 app - get data from the SharePoint

Image
For safety reasons apps are seperated from the SharePoint where they are installed on. Apps are installed on other domains and that is how the seperation works. Apps can't contact the SharePoint, because Cross-Site-Scriptingis blocking it. But there is still a way to get data from the SharePoint and with this way comes a permission concept into the app world. Permissions There is a library, called the Cross Domain Library, that allows to communicate with a SharePoint from app site. This library is aviable on every SharePoint 2013 and is easy to call. But wait.. if it is so easy to call a library that can get SharePoint data it is not saver than before. This library contains more than communication.. it authentificates the app against the SharePoint and asks for permissions. This happens right after the installation of the app. The installing user will be asked to grand permissions for the app. But how does the app know what permissions are needed? Asking for permissions is you

Basics for SharePoint 2013 app development

Image
The biggest innovation in SharePoint 2013 is the app-architecture. With this innovation it is possible to install applications (apps) on a SharePoint. This applications can be developed by yourself or you can buy them in the SharePoint Store. They are totally detached of the SharePoint and got their own area. They can contain own lists, have own sites with custom code and they have their own interfaces. But it is possible to communicate with the SharePoint. My first app To develop an app you need Visual Studio 2012 or above and a development SharePoint. To begin start Visual Studio as administrator and click 'New project...'. A mask opens where you can choose a template. Go to 'Templates' → 'Visual C#' → 'Office/SharePoint' → 'Apps' and select 'App for SharePoint'.

How to set up a SharePoint 2013 app development environment (without DNS)

Image
With SharePoint 2013 Microsoft integrated the app contept into the SharePoint world. This gives us new opportunities, but also sets new requirements. SharePoint apps got their own enviroment where they will be installed and run. With this step Microsoft made sure the SharePoint experience will not be affected negativ by bad running apps or apps that want to steal data. But this isolation requires, that apps got their new oen DNS entry. The app do not have the same URL as the SharePoint. An app URL looks like this: <prefix>-<GUID of the app (will be generated automatic)>.<appdomain> (example: http://app-005f804530bdb6.app.development/). To create and manage a new DNS entry is way to much work for a development enviroment and that is the reason why there is a way to do it without DNS.

fix the 'Sideloading of apps is not enabled on this site' problem with PowerShell

In case you are developing an app for SharePoint 2013 and you are not developing on the server you can get the error 'Sideloading of apps is not enabled on this site'. When that happens you do not have the sideload developing feature activated. It is a hidden feature and allows you to develop apps from client devices. All you need to do is to enter the following line into PowerShell on the server. Enable-SPFeature e374875e-06b6-11e0-b0fa-57f5dfd72085 –url <yourSharePointURL>

InfoPath render problem with the Server State Service on SharePoint 2010

Image
I tried to transfer a InfoPath form from one SharePoint to another. After it was done i wanted to open the form and this is what I got:  The form cannot be rendered. This may be due to a misconfiguration of the Microsoft SharePoint Server State Service. For more information, contact your server administrator. Normally this should not happen, because the Server State Service will be installed in the SharePoint wizard automaticly, but somehow it does not. In this case there are some easy PowerShell commands to solve the problem.

The fast List search in SharePoint 2010

Have you ever noticed the search in SharePoint 2013 lists? It is pretty cool, because you get what you want and that on a fast way. Did you or a client ever had the wish to use it on a SharePoint 2010 to? Well that is pretty easy. All you need to do is to add a Code Editor Web Part over your list. Enter into the list the following code:

How to create custom Page Layouts in SharePoint 2013

Before you create a Page Layout there are two questions: - What is a Page Layout? and - What do you need to create a Page Layout? What is a Page Layout? A Page Layout is a way to design content on sites. You can create content areas and place them with CSS. Simplified: it is like a form for list items. A site is nothing else than an item in a library, so you can see the layout, that you build, as the display form, the edit form and the new form. What do you need to create a Page Layout? You will need to download and install the SharePoint Designer 2013 , but the most important thing, to make you the less work as possible, is that you know what you want to design and what content you want to display. I recommend you to create a custom Content Type for your Page Layout. It will make it a lot easier to add all the columns you need. It is also recommended to got some knowledge in HTML, ASPX, JavaScript and CSS.

Fix the MailItem.Send() warning

Sometimes you need to create and send mails in your code. There are many ways to solve this requirement. You can connect to your Exchange with WebServices or you can use a WebService to connect to a SMTP server. But what if you are not able to connect to them, but you know the client is using Outlook. You can call Oulook to send your mails. That is pretty easy all you need is the interop namespace of Outlook (using Oulook = Micosoft.Office.Interop.Outlook;). The code you need for this should contain lines of the following snippet: 1 2 3 4 5 6 // ..call Outlook .. // create the mailitem Outlook.MailItem mItem = outlookapplication.CreateItem(Outlook.OlItemType.olMailItem); // ..set subject, body recipient and much more.. // send the mail mItem.Send();

SharePoint 2013 WebPart with custom properties

Image
If you created a WebPart for SharePoint 2013 and you want the user to customize it, you will need properties. Setting them up is not that easy as you think. You need to edit two files. Lets begin with the <yourWebPart>.ascx.cs file. What you will do there is setting up the propertiesobjects. Later you can use them to read the values the user typed in. I make a difference between two kind of properties: 'easy' and 'not that easy properties'. I do not call it 'not that easy', because it is hard to use, I call it that way because you need a line of code more. An easy propertiy would be a textfield. The code you need to add would look like this. 1 2 3 4 5 6 7 [WebBrowsable(true), WebDisplayName( "<youtDisplayname>" ), WebDescription( "<yourDescription>" ), Personalizable(PersonalizationScope.Shared), Category( "<yourCategoryname>" )] public string customTextProperty { get ; set ; }

Datasheet View for Picture Libraries in SharePoint 2010

In SharePoint 2010 there are Datasheet Views for Picture Libraries not aviable, but there is a way to open them. First of all you need to open a List in Datasheet View and copy the link. example: http://mySharePoint/mySite/Lists/Links/AllItems.aspx ?ShowInGrid=True&View= %7B6686F338%2D5937%2D46F6%2D90EA%2D7B57B97B4207%7D &InitialTabId=Ribbon%2EList&VisibilityCont You need to replace the marked fields. In the first field you need to enter the link of the Picture Library you want to open. Important is that you use the 'All Items' view.

Remove the title area in SharePoint apps

Image
Sometimes it is nice, sometimes it is annoying. Yes I am talking of the titlearea of SharePoint 2013 Apps. But don't worry, it is easy to remove it from your app. All you need to do is to paste some css into your stylesheet. I recommend to use a css-file that is used in every site. This way you need to do the change on just one place. 1 2 3 #s4-titlerow { display : none !important ; } After pasting the code into your app you won a lot of space and you can build your own design.

How the ClientContext of SharePoint CSOM works

If you are writing clientsite applications for SharePoint you can use for example the Client Site Object Modell (CSOM). In the CSOM you will need to use the ClientContext to communicate with the SharePoint, but how does it work? Using the ClientContext is like going to the supermarket.First of all you are looking out to which supermarket you will go. Then you figure out what you need and write it down to a shopping list. After that you are going to the supermarket and get all the stuff you need. So first of all lets get the SharePoint (supermarket) we want to get our stuff from. ClientContext ctxSupermarket = new ClientContext( "http://mySharePointURL/mySupermarket/" );

DragAndDrop in Outlook - is it a mail, an attachment or a file?

If you are developing an addin for outlook and you are building a drag and drop able control, you will need to check what kind of data droped in. In the following code I made differences between those three types: files from the filesystem, mails out of Outlook and attachments that came from mails in Outlook. I used the DragEventArgs to figure out what was droped and then I handle each way a bit different.

Refreshing the UI in WPF

If you are using WPF and missing the 'Application.DoEvents();' method, you know from Windows Forms to refresh the UI, here is a solution for you. I had the same problem and was looking for a way to refresh the UI in runtime.

The project type is not supported error

Image
I tryed to open a Visual Studio project on another enviroment and ran into an error. A dialog poped up and looked like this. The Output Window sait 'The project type is not supported by this installation.'. So Visual Studio was not able to read the projectfiles. The reason is that the project templates are not installed.

Read and write cookies

Cookies are usefull in the world of web programming. You can save values on a site and read them on an other one. You can use cookies in JavaScript and it is pretty easy. All you need are two functions. The first one is called "set_cookie" and creates them. In the call of the function you need give your cookie a name (make sure it is an unique name, or you overwrite some existing cookies). Then you need the value of the cookie. At least you give the cookie a 'lifetime'. An expiredate is important because there is no garbage collector for cookies.