..:: I like SharePoint ::.. Rotating Header Image

Visual Studio

SharePoint Reconnecting declarative created lookup fields

Often if you provision lists or libraries, your customer wants you to add a lookup column to another list, which may be in the same web. So you are starting with list definitions and do everything in the right way, but if you deploy your solution and create list instances from the source list and the list with the lookup, your lookup column is not connected to the source list. I don’t know why this happens, and i don’t care about the technical details why and why not. I’d rather share how to reconnect your defined lookup column to the source list.

Well, that’s what we want avoid:

Zwischenablage04

What do we need? We need c# code, we put this into a feature event receiver or anything what will be used for it. (more…)

SharePoint How to create a document set programmatically

In SharePoint it is not only possible to create files, documents or listitems programmatically. You also can build up a solution in which you create folders or even document sets.

Why should this interested me? Well, the advantages of document sets should be known and if you decided to use them, then it might also be a kind of interesting how to use these things by c#. If you need a scenario: If your customer uses CRM and wants to store the customer related documents in a SharePoint, it might really helpful to create for each customer a document set in which the contracts, marketing flyers, offers or the mails can be uploaded. In this case if you create a new customer account in your CRM you also want to create a document set in SharePoint automatically. There is no need for the user to go to CRM, create a new account and after that go to SharePoint and create a new document set and type in all the customer informatione like name, id, adress, contact person, etc.. again and again. It just happens.

Ok enough of theory, let’s see how we can create a document set by code. But at first we need to activate the document set feature in SharePoint if not already done. In the site settings you should go to the Site Collection features link and activate the document set feature. After that you can add the document set content type to your library. This post helps you.

Ok, we can start. In my example i simply used a console application just to show how it works.



using (SPSite site = new SPSite("http://yourserver/sites/sitename/"))
{
SPWeb web = site.RootWeb;
SPList docList = web.Lists["Documents"];
if(docList != null)
{
CreateDocumentSet(docList, "ILikeSharepoint");

}


}

public static DocumentSet CreateDocumentSet(SPList list, string DocumentSetName)
{
SPContentType docsetCT = list.ContentTypes["Document Set"];
Hashtable properties = new Hashtable();
properties.Add("DocumentSetDescription", "New Document Set");

SPFolder parentFolder = list.RootFolder;

DocumentSet docSet = DocumentSet.Create(parentFolder, DocumentSetName, docsetCT.Id, properties, true);

return docSet;
}


That’s it. Hope it helps you. If you need more please look at this page.

..:: I LIKE SHAREPOINT ::..

SharePoint Create a tabbed view in c#

There are a lot of samples how to create tabbed view for list forms or webparts in SharePoint. Mostly they are build up with javascript, ajax or jquery. Well these technologies are really interesting, but today i am gonna make a short example of creating such tabbed views in c# using asp.net.

The advantages are crystal clear: If you have a form with lots of fields you can group them into tabs and the user

  • see the section important fields
  • does not need to scroll really deep
  • have all fields in the scope of his or her eyes

Ok, let’s start with a simple application page which we add to our project solution. I recently builded the demo based on this post.

In this application page we insert in the aspx file the following code into the placeholder main: (more…)

SharePoint 2010 Create a custom site definition

Sitedef2

Ever wanted to create your own custom site definition? It’s pretty cool, if you can choose your own template at the time you create a site collection at the central administration. What can you by using a solution with a custom site definition?

Well, at first you can define fields, content types, lists, libraries and webparts which should be available after site is created. Of course, what was important for me, was the possibility to change the default.aspx page which is the starting point. At the default.aspx which is the entry point of each site collection you can place webparts, text, images, etc.

So  if you are creating your own site definition don’t leave it blank. Use an image and a welcome text. Maybe you can provide a small intoduction into this workspace and necessary contact information if the user needs help. Useful links might be also interesting. Your user should have a good feeling when starting with SharePoint. My desired solution should have a custom image and a welcome text.

Ok, that’s enough explanation. Let’s go into the details.

(more…)

SharePoint create a wait message for long running tasks

In SharePoint 2010 and 2013 you have the nice looking Modal dialogs. I wrote already some posts about it. But now i would like to share how you can use these for long running tasks. For example if you perform a search which may take some seconds, it would be nice to give a small message for the user to wait. These are called the showWaitScreen like in the picture below.

waitScreens

How we can implement such a cool message window? Let’s start with the scenario. We have a custom application page. In this page we have a search button and a grid in which we will load data. The data loading operation takes a few seconds. So we start implement our script.

(more…)