Today I found a simple method to enable gzip compression on your homepage, when you are using Apache webserver. You just have to create a .htaccess file with this code, assuming you have mod_deflate enabled in your Apache config.
<IfModule mod_deflate.c>
<FilesMatch "\\.(js|css|html|xml|jpg|png)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
This code snippet provides gzip compression for all js, css, html, xml, jpg and png files.
Ok. Images are most time already compressed, but I added them as well.
Very simple and very useful. :-)
Thursday, November 23, 2017
Apache - Enable gzip compression with .htaccess
Labels:
.htaccess,
Apache,
compression,
gzip,
Webserver
Thursday, November 16, 2017
SQL - Use PARSENAME function to extract individual parts from a string
Today I discovered a very cool feature in T-SQL from Microsoft SQL Server.
It happens (unfortunately) again and again that several records are written in a single column and one is forced to extract individual parts from it. So far, I have always written a SQL function of my own, but this is will be history from now on with the help of the PARSENAME function. :-)
See this examples. I think, this explains it very well:
DECLARE @exampleString nvarchar(max) = 'Test;Test1;Test2'
SELECT PARSENAME(REPLACE(@exampleString,';','.'),1)
--Result: Test2
SELECT PARSENAME(REPLACE(@exampleString,';','.'),2)
--Result: Test1
SELECT PARSENAME(REPLACE(@exampleString,';','.'),3)
--Result: Test
It happens (unfortunately) again and again that several records are written in a single column and one is forced to extract individual parts from it. So far, I have always written a SQL function of my own, but this is will be history from now on with the help of the PARSENAME function. :-)
See this examples. I think, this explains it very well:
DECLARE @exampleString nvarchar(max) = 'Test;Test1;Test2'
SELECT PARSENAME(REPLACE(@exampleString,';','.'),1)
--Result: Test2
SELECT PARSENAME(REPLACE(@exampleString,';','.'),2)
--Result: Test1
SELECT PARSENAME(REPLACE(@exampleString,';','.'),3)
--Result: Test
Tuesday, October 10, 2017
SharePoint 2010 - How to check if group exists without exception
The SharePoint Server handles some things differently than you might know from standard C # programs.
I recently stumbled upon that I've tried to determine if a user group exists in SharePoint. I thought no problem and tried it with this code:
string nameOfGroupToCheck = "Test Group";
SPGroup group = spWeb.Groups[nameOfGroupToCheck];
if(group != null) {
...
}
I assumed that the variable group is null if the group is not present, but SharePoint throws an exception instead.
This does not happen with the following code snippet:
using System.Linq;
...
string nameOfGroupToCheck = "Test Group";
if (spWeb.Groups.OfType<SPGroup>().Where(g => g.Name == nameOfGroupToCheck).Count() > 0)
{
...
}
To get this code work correctly, you need to add the System.Linq namespace into your code.
By the way, this check also works with lists in SharePoint. You would only have to query the lists instead of the groups.
I recently stumbled upon that I've tried to determine if a user group exists in SharePoint. I thought no problem and tried it with this code:
string nameOfGroupToCheck = "Test Group";
SPGroup group = spWeb.Groups[nameOfGroupToCheck];
if(group != null) {
...
}
I assumed that the variable group is null if the group is not present, but SharePoint throws an exception instead.
This does not happen with the following code snippet:
using System.Linq;
...
string nameOfGroupToCheck = "Test Group";
if (spWeb.Groups.OfType<SPGroup>().Where(g => g.Name == nameOfGroupToCheck).Count() > 0)
{
...
}
To get this code work correctly, you need to add the System.Linq namespace into your code.
By the way, this check also works with lists in SharePoint. You would only have to query the lists instead of the groups.
Labels:
C#,
Code Snippet,
CSharp,
Exception,
SharePoint 2010
Subscribe to:
Posts (Atom)