SharePoint 2010: Cross Site List and XsltListViewWebPart

I been working on a project recently and one of the pages required a list view from another site from the same site collection. So this is what I had to do to make it work.

var site = SPContext.Current.Site;
var spList = site.AllWeb["yourwebsite"].Lists["listname"];
var xsltLvWp = new XsltListViewWebPart(){
    Title = "My Cross Site List View",
    WebId = spList.ParentWeb.ID,
    ListName = spList.ID.ToString("B").ToUpper(),
    ListId = spList.ID,
    ViewGuid = spList.Views["View Name"].ID.ToString("B").ToUpper()
}

Git: Cloning a Repository

 

 

Git is an awesome source control, there are two sites that allow you to host repositories like GitHub and BitBucket. If you are looking for a free private repository hosting I would recommend BitBucket. 

Anyways let’s get started with cloning a repository on to your computer. First you will need some tools, if you are a windows user I would recommend you to get msysgit, and for Linux and Mac you can follow the download instruction from git-scm.com

I am going to use an existing public repository from GitHub called MonoGame, it’s a cross platform XNA development library for Mono. So open your terminal and enter the following commands:

$mkdir projects
$cd projects
$git clone https://github.com/mono/MonoGame.git

After the cloning has finish perform a ls -al command in your projects folder and you will see a MonoGame folder created with copies of the source code. Now you have cloned your first Git repository!

Writing a Simple Linux Daemon Program

I have decided to write a watcher daemon to watch a specified folder for any newly created files or folders. I did some googling and found that it was very simple to create a daemon program in Linux.

First you will need to create your source file and include the following header file:

#include <unistd.h>

In the main function you need to call daemon() like this:

int main()
{
    if (daemon(0,0) == -1)
         err(1, NULL);
    while(1)
    {
         Do something here....
    }
}

In the while loop you can put your own code to perform a specific task. 

To run the daemon when your system boots up edit the file /etc/init.d/rc.local and add the following line at the end of the file:

/usr/sbin/yourdaemon

note: make sure the you copied the file to /usr/sbin or else the file can not be found when the system is booting up.

The daemon function parameters, I have specifice 0 for the first paramter to use the root “/” folder instead of the working folder and the second parameter I have done the same which will redirect all standard input, output and errors to /dev/null.

Detailed information on how to use the daemon function can be found here.

Binding SPList to Binding Controls.

To bind a SPList to a binding control list for example the DetailsView data control you will need to provide a DataSource to it. The problem is SPList doesn’t implment the IDataSource interface, but I have discovered that there is a SPDataSource which allows you to pass a SPList object as a parameter in the constructor. Below is a code

var spList = SPContext.Current.Web.Lists["List Name"];
var ds = new SPDataSource(spList);
DetailsView1.DataSource = ds;
DetailsView1.DataBind();

Shares