How to create a Microsoft SharePoint folder in a document library, by using WebClient in C#

 

If you want to create a folder in a document library, by using WebClient in C#, you can use the following code:

 

namespace Research
{
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
[TestClass]
public class RliResearch
{
[TestMethod]
public void CreateSharePointFolderInDocumentLibrary()
{
string folderToCreateUri = "https://1.1.1.1/sites/mysite/Shared%20Documents/FolderIWantToCreate";
using (var client = new WebClient())
{
client.Credentials = CredentialCache.DefaultCredentials;
client.UploadString(folderToCreateUri, "MKCOL", "");
}
}
}
}

Note: The folder you want to create the folder in, must exist. In other words: create subfolder hierarchy one at a time.

To create the folder hierarchy:

Shared Documents

     SubLevel1

             SubLevel2

 

namespace Research
{
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
[TestClass]
public class RliResearch
{
[TestMethod]
public void CreateSharePointFolderInDocumentLibrary()
{
string sublevel1 = "https://1.1.1.1/sites/mysite/Shared%20Documents/SubLevel1";
using (var client = new WebClient())
{
client.Credentials = CredentialCache.DefaultCredentials;
client.UploadString(sublevel1, "MKCOL", "");
}
string sublevel2 = "https://1.1.1.1/sites/mysite/Shared%20Documents/SubLevel1/SubLevel2";
using (var client = new WebClient())
{
client.Credentials = CredentialCache.DefaultCredentials;
client.UploadString(sublevel2, "MKCOL", "");
}
}
}
}

Making the switch: VMWare Workstation 7 to Hyper-V server for performance reasons (PowerPivot on SharePoint 2010)

 

History

Back in 2002 I was working with a company which produced a CAD application written in VB6. The product was released in several languages. For each language we had a Microsoft Windows NT 4 workstation with the corresponding language package. I quickly realized that managing these workstations was difficult. So I started to look at virtualization, but it was not until 2003 with new hardware and an other company when I decided to take a look at VMware Workstation version 4.0. This was great I could run all Microsoft Windows languages and different versions on 1 system! Then in 2004 Microsoft released Microsoft Virtual Server 2005 I took a look at the product but soon realized that it could not compete with VMware Workstation and I kept on using VMware Workstation. This worked great for me, except for 2 things:

  1. Performance, if I installed a Windows operating system on a workstation en booted from it, it was much, much faster then when I used a Virtual Machine containing the same windows operation system on that same workstation.
  2. Snapshot – Backup host, if I installed a program or driver on the host and that corrupted the host, there was no out of the box recovery (yes there where al kinds of products that can do that, but not windows out of the box) possibility. One trick I used was to install an windows host OS and then only installed VMware Workstation on it. I would only use the VMware virtual machines and only used the host OS to take snapshots and backups of my virtual machines.

VMware Workstation 7 (paid product)

Part 2 worked fine for me, but then I shifted from being a C# developer to a self-service BI specialist and Microsoft introduced PowerPivot and SharePoint 2010. In late 2009 I started to work with PowerPivot (Gemini at the time) and SharePoint 2010, so I create a VMware 7 development virtual machine with Microsoft Windows 2008 R2, Microsoft SQL Server 2008 R2, Microsoft SharePoint 2010 and Microsoft Office 2010 on a 3 year old dell laptop with 4 GB memory. Well that really did not perform at all. I bought a 80 GB Intel Postville G2 M-25 SSD, but the VMware Workstation virtual machine would not perform well and I was waiting on the system all of the time. Then one time I installed Microsoft Windows 2008 R2 as host OS with Microsoft SharePoint 2010 and PowerPivot on it. Well I was really impressed by the speed of the system, I booted in 3 times as fast an all Office products would directly open when I clicked on a document, instead of waiting for the splash screen. I know 4GB of RAM is not enough for a Microsoft SharePoint 2010 PowerPivot development machine, but with the help of the SSD I could manage it. But then I could not take snapshots of my host.

As I said before, VMware Workstation 7 is to slow for me on my hardware for running Microsoft SharePoint 2010 with PowerPivot, that’s why I started to look at hypervisors.

Pros
– Don’t have to no anything about hypervisors, just install windows host OS and then install VMware Workstation 7.0, it’s only a program.
– Supports not only Windows guest operating systems

Cons
– Must be installed on a host operating system (host operating systems consumes cpu, memory and disk space
– Is not free
– “Bad” performance compared to native boot

 

VMware ESXi (freeware)

Then in begin 2010 I learned about hypervisors. VMware has a free product ESXi 4, that can be installed on a system with a (32MB foot print, maximizing the space on the 80GB OS for Virtual Machines) and then you can run different virtual machine containing not only Microsoft OS but also Linux etc without installing a Host OS and having the possibility to take snapshots and backups of the virtual machines . So I created a bootable USB ESXi drive but found out my NIC and SATA controller where not supported, damn! Yes I know, ESXi is not supposed to be installed on a laptop but it would have been nice.

Pros
– Freeware
– No host OS (so not need to snapshot or backup host, only snapshot and backup virtual machines)
– 32 MB footprint
– Supports not only Windows guest operating systems
– Can run Microsoft Windows XP virtual machines
– Can boot from USB without installing

Cons
– Can’t native boot from virtual machines (so a performance impact, but far better then VMware Workstation)
– Could not get it to work with my DELL laptop

 

Microsoft Hyper-V 2008 R2 (freeware)

In 2010 Microsoft released there hypervisor: Microsoft Hyper-V 2008 R2 and it’s free! What did you say, is Microsoft releasing a product that’s free of charge, the answer is; YES. It can be downloaded, here: http://www.microsoft.com/downloads/details.aspx?FamilyID=48359dd2-1c3d-4506-ae0a-232d0314ccf6&displaylang=en it’s a 1,5 GB ISO. Installed it and after installing I could boot from a VHD file created with Microsoft Windows 2008 R2

Pros
– Freeware
– Native boot from VHD, maximizing performance and hardware possibilities
– No host OS (so not need to snapshot or backup host, only snapshot and backup virtual machines)
– 6GB footprint (after installing)
– Can boot from USB without installing

Cons
– Supports only booting from Microsoft Windows 7 or Microsoft Windows Server 2008 R2
– Have to use a “workstation” virtualization product in a booted virtual machine to manage other virtual machines

 

What do I exactly use for developing Microsoft SharePoint 2010 PowerPivot applications

So today what do I exactly use for developing C# vs2008, C# vs2010 and SharePoint 2010 PowerPivot applications

  1. Laptop with Microsoft Hyper-V Server 2008 R2 (freeware) installed on a 2,5 inch 80GB SSD boot disk, a 500GB 7200 rpm 2,5 inch for data and virtual machines I don’t often use and 8GB of RAM.
  2. When I start the laptop I boot into a VHD containing Microsoft Windows 2008 R2, Microsoft SQL Server 2008 R2, Microsoft SharePoint 2010, Microsoft Office 2010 and the hyper visor role installed to manage other virtual machines. Because I primarily do self service BI work and VS2010 development this is the machine I want the best performance for. I use the hyper-v manager in the this virtual machine to start legacy virtual machines (VS2005 with SQL 2005 or VS2008 with SQL 2008)
  3. In the SharePoint 2010 virtual machine I keep 2 images up date date, a base Microsoft Windows 7 and a base Microsoft Windows Server 2008 R2 virtual machine. They serve as base for creating new virtual machines, see https://www.roelvanlisdonk.nl/?p=1530. They are updated every week and configured the way I want to, see https://www.roelvanlisdonk.nl/?p=1462
  4. In all I mange 6 virtual machines
    • Microsoft Windows 7 x64 – base for client virtual machines
    • Microsoft Windows Server 2008 R2 x64 – base for server virtual machines
    • Legacy 2005 development – clone of Microsoft Windows 7 x64 base containing VS2005, Office 2003, SQL Server 2005, SSIS 2005, SSRS 2005, SSAS 2005
    • Legacy 2008 development – clone of Microsoft Windows 7 x64 base containing VS2008, Office 2007, SQL Server 2008, SSIS 2008, SSRS 2008, SSAS 2008
    • SharePoint 2010 development (native boot), clone of Microsoft Windows Server 2008 R2 x64, containing VS2010, SharePoint 2010 with PowerPivot, Office 2010, SQL Server 2008 R2, SSIS 2008 R2, SSRS 2008 R2, SSAS 2008 R2
    • VPN – clone of Microsoft Windows 7 x64 base containing VPN connections and remote desktop shortcuts to customer machines (I use a virtual machine for this purpose, because, when connected to the VPN I don’t have access to the rest of the network)

 

Conclusion

Microsoft Hyper-V Server 2008 R2 rules:

  1. Creating new virtual machines in minutes, containing a fully patched windows host OS and configured the way I like it to be with the ability to boot from the virtual machines, maximizing performance
  2. Can use legacy development machines without rebooting (vs2005, vs2008 for legacy support)
  3. Install a full blown Microsoft SharePoint 2010 development server within 30 minutes on a new laptop or workstation and booting from it, maximizing performance

Error: The Business Data Connectivity Metadata Store is currently unavailable in Microsoft SharePoint 2010 RTM

Trying to create a external contenttype by using the Microsoft SharePoint 2010 Designer I got the error “The Business Data Connectivity Metadata Store is currently unavailable”

 

image

 

Cause

This was caused by the fact that I had installed a “PowerPivot” SharePoint 2010 installation and during the installation you do not run the SharePoint 2010 Configuration Wizard.

 

Solution

First ensure all update are installed, by using Microsoft Windows Update, then go to the Microsoft SharePoint 2010 Central Administration page and click on Configuration Wizards:

image

 

Run the wizard, make sure the Business Data Connectivity Service is checked.

image

After running this wizard I still got the same exception, this was caused by some services where not running, check if all services are running: Central Administration > Manage services on server:

image

After starting some services, see screendump the error was resolved.

Stop the presses: mega performance boost for Microsoft SharePoint 2010 on opening office documents, by using a Internet Explorer setting

We are using Microsoft SharePoint for our intranet since 2006, but users started to put there office documents local or on other products like TFS, NAS (File Share), just because opening a Microsoft Office document would take a lot of time (ranging from 10s to 2 minutes). The VISIO documents were the worst of all (always waiting for minutes before I could start working on the document, but then when I saved the Microsoft VISIO document I was waiting for minutes again).  So after being frustrated for over 4 years, here comes along our Microsoft SharePoint Administrator: Jan Willem Nieuwenhuizen, he did a google on it and found the solution:

Start Internet Explorer > Tools > Internet Options > Connections > LAN settings”:

Disable “Automatically detect settings”

Enable “Use a proxy server for LAN (These settings will not apply to dial-up or VPN connections)”

Enable “Bypass proxy server for local addresses”

 

image

Press Advanced

image

Enter *.* in the “Do not use proxy server for addresses beginning with”:

Press OK

Can I have a hooray for JW: hooray hooray hooray

How to create a windows explorer shortcut on the desktop to a SharePoint document library

If you want to create a shortcut on you’re desktop to a SharePoint document library, follow the steps on: http://www.endusersharepoint.com/2008/02/13/endusersharepointcom-update-on-creating-a-desktop-shortcut-to-a-sharepoint-library/

 

This will create a shortcut with a target formated like: "\\MySharePointSite.MyDomain.nl\DavWWWRoot\Site1\SubSite1\Shared Documents"

  • MySharePointSite.MyDomain.nl = Top-level site collection hostheader
  • DavWWWRoot = Indicates the URL should be opened in the Windows Explorer and not Internet Explorer
  • Site1 = First site beneath the top site collection
  • SubSite1 = First site beneath Site1
  • Shared Documents = Document library name

Remember: Pasting the internet URL (http://MySharePointSite.MyDomain.nl/Site1/SubSite1/Shared%20Documents) directly in the Windows Explorer will open Internet Explorer, so you can use the internet URL to open the document library directly in Windows Explorer, you must use the \\MySharePointSite.MyDomain.nl\DavWWWRoot\Site1\SubSite1\Shared Documents format

 

image

How to enable https on Microsoft SharePoint Server 2010 RTM by configuring alternate access mappings

Open the Microsoft SharePoint Server 2010 Central Administration > System Settings > Configure alternate access mappings:

 

image

 

Add Internal URLs

image

Enter https://youreservername and choose intranet zone, click on ok

image

Result

image

Start inetmgr right click you’re site and click on Edit bindings…

image

Click Add..

image

 

Choose the server generated certificate if you don’t want to by a certificate, but then you will get an warning when accessing you’re SharePoint site.

 

image

 

Click OK and click on Brows *:443 (https)

image

The warning page

image

 

Click on Continue to this website (not recommended).

image

 

Followed the steps on http://blogs.msdn.com/sowmyancs/archive/2010/02/12/how-to-enable-ssl-on-a-sharepoint-web-application.aspx for more information on using hostheaders (dns entries) and ssl certificates.

Install a development Microsoft SharePoint 2010 RTM Server with PowerPivot and Microsoft SQL Server R2 Reporting Services integration

These are the steps I followed to install a development Microsoft SharePoint 2010 server with PowerPivot and Reporting Services integration.

 

I installed Microsoft SharePoint Server 2010 by following the steps on:

http://powerpivot-info.com/post/66-step-by-step-guide-on-installing-powerpivot-for-sharepoint

 

Then I followed the steps on: http://technet.microsoft.com/en-us/library/bb326356(SQL.105).aspx and http://msdn.microsoft.com/en-us/library/aa905871(SQL.105).aspx to enable Microsoft SQL Server 2008 R2 Reporting Services integration for Microsoft SharePoint Server 2010.

After following these steps, I was able to publish PowerPivot excel reports and Microsoft SQL Server 2008 R2 Reporting Services reports to one top level site collection on Microsoft SharePoint Server 2010. See screen dumps:

 

Start Microsoft SQL Server 2008 R2 setup > Installation > New installation or add features to an existing installation

image

New installation or add shared features

image

SQL Server Feature Installation

image

Reporting Services

image

Instance Configuration

image

Server Configuration

image

 

 

 

Start Reporting Services Configuration Manager

image

Choose Report Server Instance

image

Create a new report server database

image

Report Server Database Configuration Wizard

image

Report Server Mode > SharePoint Integrated Mode

image

Additional actions in Reporting Services Configuration Manager

Web Service URL > Apply

image

Report Manager URL > Apply

image

 

The SharePoint 2010 pre-requisite installer now automatically guides you to download and install the Reporting Services 2008 R2 for SharePoint 2010 Add-in.  Btw, you can download the Reporting Services add-in manually as well. In most cases you can just activate the Report Server Feature in SharePoint Central Administration (http://technet.microsoft.com/en-us/library/bb677366(SQL.105).aspx). In some case you must first download and install the add-in manually, in my case I re-configured the Reporting Services 2008 R2 for SharePoint 2010 Add-in and then activated the Report Server feature on the Central Administration site.

Reconfigure the Microsoft SQL Server 2008 R2 Reporting Services Add-in > Start > Control Panel > Programs and Features > Right click SQL 2008 R2 Reporting Services SharePoint 2010 Add-in > Configure

image

Activate Report Server Integration Feature and Report Server Central Administration Feature > Central Administration > Site Actions > Site Settings > Site Collection features

image

Configure Reporting Services Integration > Central Administration > General Application Settings > Reporting Services Integration

image

Reporting Services > Reporting Services Integration

image

Reporting Services > Set server defaults

image

 

Create a Report Library > Site Actions > More Options > Report Library

image

Enable Report Server Content Types

http://technet.microsoft.com/en-us/library/bb326289(SQL.105).aspx

 

Create a Report > Report Library > Documents > New Report Builder Report (Click once deployment Report Builder 3.0 should start)

image

 

Run click once deployment Report Builder 3.0 (78.2 MB)

image

Create you’re first report

image

 

The Microsoft SQL Server 2008 R2 sample databases can be found at: http://sqlserversamples.codeplex.com/ (82.5 MB). At this moment the November CTP sample database are the last version. RTM sample database should be released soon.

 

Save the report to SharePoint 2010

image

Open report in Microsoft SharePoint 2010

image

Result full screen

image

Result as webpart

image

Styling, branding SharePoint 2010 based on Active Directory users and groups, no code required, only CSS and Document Permissions

To style a SharePoint 2010 site, based on the current user and his active directory role, I use document permissions on css files in the Style Library.

The goal of the blog post is to Show a a logo of a man, when the current user is member of the Active Directory role [Men] and show a logo of a Woman, when the current user is member of the Active Directory role [Women].

 

Woman (Elise) signs in

image

 

Men (Bas) signs in

image

 

Guide

  • In Active Directory create two roles: [Men] and Women
  • In Active Directory create the users [Bas] and make him member of the role [Men]
  • In Active Directory create the users [Elise] and make her member of the role [Women]
  • In SharePoint 2010 go to Site Actions > Site Permission on you’re site collection top level site
  • Grant Permissions [Full Control] to the Active Directory groups: [Men] and [Women]

image

  • Create two css files on you’re desktop: Men.css and Women.css
  • Men.css contains:

.logo
{
    background-image:url("/Style%20Library/Images/Men.png");
    background-repeat: no-repeat;
    background-position: top left;
    height: 425px;
}

  • Women.css cotains:

.logo
{
    background-image:url("/Style%20Library/Images/Women.png");
    background-repeat: no-repeat;
    background-position: top left;
    height: 425px;
}

 

  • Go to you’re SharePoint top level site, click on Site Actions > Site Settings

image

  • Site Administration > Content and structure

image

  • Upload Women.png and Men.png to the Style Library\Images by dragging and dropping the files (New > Item > Upload Multiple Files…)
  • Create Images folder if it does not exist in the [Style Library]

image

image

  • After upload check the files in

image

  • Upload Men.css and Women.css to the Style Library and check in files
  • Manage permissions on Men.css to include only men (click on Manage Permissions > Stop inherriting permissions), remove user permissions for women
  • Manage permissions on Women.css to include only women(click on Manage Permissions > Stop inherriting permissions), remove user permissions for men

image

  • Open Microsoft SharePoint Designer and open you’re site then click on Master Pages > v4.master
  • Click on Attach Style Sheet, browse for the Men.css stylesheet and click on Import > OK
  • Repeat for Women.css
  • The only thing what this does, is adding the following lines at the end of the <head> tag in the master page

@import url(‘../../Style%20Library/Men.css’);
@import url(‘../../Style%20Library/Women.css’);

image

  • Make sure all persons have read rights on the Master Page Gallery and the v4.master is checked in after you edit the file to import Men.css and Women.css

image 

  • On you’re team site, click in the ribbon on Page > Edit

image

  • Click in the ribbon on Format Text > HTML > Edit HTML Source
  • Add <div class=”logo”></div> to the content editor webpart

image

  • Click on OK then in the ribbon on Save

 

Result, see beginning of this blog post