Five files in 12 hive thats good to know!

Found this post over at http://www.wictorwilen.se! check it out!

ctypeswss.xml (in TEMPLATE\FEATURES\ctypes)

This is the feature elements file for all the default WSS Content Types. When creating new content types, most often I find it useful to derive them from existing content types. For example if I need to create a content type that derives from the standard content type Task, i can easily get the content type ID, which is used when creating new content type IDs, and what Site Columns that content type has.

fieldwss.xml (in TEMPLATE\FEATURES\fields)

Second favorite is the elements file for the WSS Site Columns feature. In this file all definitions for the default WSS Site Columns is found. Together with ctypeswss.xml this is really handy when creating custom content types. By finding out the ID’s of the Site Columns you can easily re-use the site columns when creating content types.

Custom List schema.xml in (TEMPLATE\FEATURES\CustomList\CustList)

Whenever I need to create a list definition and need to create a schema.xml I use the schema.xml for the Custom List feature and copy it to my definition.

STS onet.xml in (TEMPLATE\SiteTemplates\STS\Xml)

This is the file to check out when creating Site Definitions. The onet.xml file contains all Site Definitions (althought the folder is called SiteTemplates), which includes navigation, lists etc. Most often I copy this file (and all other files in the STS folder) and remove almost everything except the the blank site def.

DOCICON.xml (in TEMPLATE\XML)

Perhaps not that interesting that the four above, but on nearly all installations you update this file with the PDF icon (at least). What this file does it that it allows you to map an extension (or ProgID) to an icon and optionally specify an editor.

// http://www.wictorwilen.se

SharePoint: Adding files to 12 hive with VSeWSS 1.3

To add files or images to the 12 hive simply add a SharePoint/ Module by the nameTemplates, to the root of the SharePoint Project created with VSeWSS 1.3 and below that att the folder Images and latter eg: MyWebPartImages. then simply drop the files to this folder in Visual Studio and deploy your project and the files should now be visible in you 12\Template\Images\MyWebPartImages folder.

note you can delete the files created below the Module folder before adding the Images and latter the MyWebPartImages folder with you files in.

Hiding the Web Part Title by code

Modify tour WebPart.webpart file and add the followng porperties to hide the title and set the chrome type to none. More information about this on http://www.c-sharpcorner.com/UploadFile/dhananjaycoder/removingwebparttitleinsharepointabcef09162009055344AM/removingwebparttitleinsharepointabcef.aspx

<?xml version=”1.0″ encoding=”utf-8″?>
<webParts>
  <webPart xmlns=”http://schemas.microsoft.com/WebPart/v3″>
    <metaData>
      <!–
      The following Guid is used as a reference to the web part class,
      and it will be automatically replaced with actual type name at deployment time.
      –>
      <type name=”7447c788-1380-40cc-8134-5e40555dd9b0″ />
      <importErrorMessage>Cannot import WebPart1 Web Part.</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <!–<property name=”Title” type=”string”>WebPart1 Web Part</property>
        <property name=”Description” type=”string”>WebPart1 Description</property>–>
        <property name=”ChromeState” type=”chromestate”>Normal</property>
        <property name=”ChromeType” type=”chrometype”>None</property>

      </properties>
    </data>
  </webPart>
</webParts>

http://www.iconfinder.net/

http://www.iconfinder.net/ free icons seach engine

Twitter And SharePoint Custom Timer Job with some Linq to XmL

I’ve been fooling around with the Twitter API and how wanted to test how I could connect it to SharePoint. After som inspiration from Andrew Connell blog post about Custom Timer Jobs for SharePoint i’ve decided to give it a try. This function will update a list with tweets every 5 minutes so it wont go over the Rate Limit set for the Twitter API.

I’m using VS 2008 with VSeWSS 1.3 / WSS3.0

First I created a List called Twitter in the rootweb of my Wss3.0 installation and created the following columns:

Title  Single line of text  
Link  Single line of text 
Published  Single line of text 
Uri  Single line of text 
TweetAuthor  Single line of text 
TweetId  Single line of text 
TweetImage  Single line of text

After this I started an VSeWSS SharePoint Empty Project named TaskLoggerJob and created a Class with the same name TaskLoggerJob: and a small class named Tweets to handle the Tweet properties:

Tweets.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace TaskLoggerJob
{
    class Tweets
    {
        public string Id { get; set; }
        public DateTime Published { get; set; }
        public string Link { get; set; }
        public string Image { get; set; }
        public string Title { get; set; }
        public string Author { get; set; }
        public string Uri { get; set; }
    }
}

———————–

TaskLoggerJob.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint;
using System.Xml.Linq;

namespace TaskLoggerJob
{
    class TaskLoggerJob : SPJobDefinition
    {
        List<Tweets> m_tweets;
        /// <summary>
        /// Initializes a new instance of the TaskLoggerJob class.
        /// </summary>
        public TaskLoggerJob()
            : base()
        {
        }

        /// <summary>
        /// Initializes a new instance of the TaskLoggerJob class.
        /// </summary>
        /// <param name=”jobName”>Name of the job.</param>
        /// <param name=”service”>The service.</param>
        /// <param name=”server”>The server.</param>
        /// <param name=”targetType”>Type of the target.</param>
        public TaskLoggerJob(string jobName, SPService service, SPServer server, SPJobLockType targetType)
            : base(jobName, service, server, targetType)
        {
        }

        /// <summary>
        /// Initializes a new instance of the TaskLoggerJob class.
        /// </summary>
        /// <param name=”jobName”>Name of the job.</param>
        /// <param name=”webApplication”>The web application.</param>
        public TaskLoggerJob(string jobName, SPWebApplication webApplication)
            : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
        {
            this.Title = “Task Logger”;
        }

        /// <summary>
        /// Executes the specified content db id.
        /// </summary>
        /// <param name=”contentDbId”>The content db id.</param>
        public override void Execute(Guid contentDbId)
        {
            getTweets();
            // get a reference to the current site collection’s content database
            SPWebApplication webApplication = this.Parent as SPWebApplication;
            SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId];

            // get a reference to the “Tasks” list in the RootWeb of the first site collection in the content database
            SPList taskList = contentDb.Sites[0].RootWeb.Lists["Twitter"];
            SPListItemCollection items = taskList.Items;
            // Clear Twitter List from objects
            List<int> listaIds = new List<int>(items.Count);

            for (int i = 0; i < items.Count; i++)
            {

                listaIds.Add(items[i].ID);

            }

            for (int i = 0; i < listaIds.Count; i++)
            {

                taskList.GetItemById(listaIds[i]).Delete();

            }

            taskList.Update();

            foreach (Tweets item in m_tweets)
            {
                // create a new tweet, and update the item
                SPListItem newTask = taskList.Items.Add();
                newTask["Title"] = item.Title;
                newTask.Update();
                // Add data to new item..
                SPListItem existingTask = taskList.GetItemById(newTask.ID);
                existingTask["TweetAuthor"] = item.Author;
                existingTask["Link"] = item.Uri;
                existingTask["Published"] = item.Published.ToString();
                existingTask["TweetId"] = item.Id;
                existingTask["TweetImage"] = item.Image;
                existingTask.Update();
            }

            taskList.Update();
             
        }

        public void getTweets()
        {
            XDocument feed = XDocument.Load(“http://search.twitter.com/search.atom?q=from:chrperss“);

            XNamespace atomNS = “http://www.w3.org/2005/Atom“;

            m_tweets = (from tweet in feed.Descendants(atomNS + “entry”)
                        select new Tweets
                        {
                            Title = (string)tweet.Element(atomNS + “title”),
                            Published = DateTime.Parse((string)tweet.Element(atomNS + “published”)),
                            Id = (string)tweet.Element(atomNS + “id”),
                            Link = tweet.Elements(atomNS + “link”)
                            .Where(link => (string)link.Attribute(“rel”) == “alternate”)
                            .Select(link => (string)link.Attribute(“href”))
                            .First(),
                            Image = tweet.Elements(atomNS + “link”)
                            .Where(link => (string)link.Attribute(“rel”) == “image”)
                            .Select(link => (string)link.Attribute(“href”))
                            .First(),
                            Author = (string)tweet.Element(atomNS + “author”).Element(atomNS + “name”),
                            Uri = (string)tweet.Element(atomNS + “author”).Element(atomNS + “uri”),
                        }).ToList<Tweets>();
        }
    }
}

————————————-

After this I created a FeatureReceiverClass to get it all going: Named it TaskLoggerJobInstaller

TaskLoggerJobInstaller.cs

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace TaskLoggerJob
{
class TaskLoggerJobInstaller : SPFeatureReceiver
{
const string TASK_LOGGER_JOB_NAME = “TaskLogger”;

///
/// Occurs after a Feature is installed.
///
///
An object that represents the properties of the event. public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}

///
/// Occurs when a Feature is uninstalled.
///
///
An object that represents the properties of the event. public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}

///
/// Occurs after a Feature is activated.
///
///
An object that represents the properties of the event. public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
// register the the current web
SPSite site = properties.Feature.Parent as SPSite;

// make sure the job isn’t already registered
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
if (job.Name == TASK_LOGGER_JOB_NAME)
job.Delete();
}

// install the job
TaskLoggerJob taskLoggerJob = new TaskLoggerJob(TASK_LOGGER_JOB_NAME, site.WebApplication);

SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 5;
taskLoggerJob.Schedule = schedule;

taskLoggerJob.Update();
}

///
/// Occurs when a Feature is deactivated.
///
///
An object that represents the properties of the event. public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;

// delete the job
foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
{
if (job.Name == TASK_LOGGER_JOB_NAME)
job.Delete();
}
}
}
}

————————-

Then I’ve had to modify the Feature.xml file that is created when we add a new feature to the project through the “WSP View”, so it points to the ReceiverClass we just created and ReceiverAssembly

<?xml version=”1.0″ encoding=”utf-8″?>
<Feature Id=”3901dc1f-5b79-4e70-96af-f4ed32d3da0e” Title=”TaskLoggerJob” Scope=”Site” Version=”1.0.0.0″ Hidden=”FALSE” DefaultResourceFile=”core” xmlns=”http://schemas.microsoft.com/sharepoint/” ReceiverAssembly=”TaskLoggerJob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=53b5e25b60ede585″ ReceiverClass=”TaskLoggerJob.TaskLoggerJobInstaller”>
  <ElementManifests />
</Feature>

The Custom Timer Job is complete and should be able to deploy, now after 5 minutes the Twitter List should be filled with 15 blogposts.

note: Remember that you might have to restart the SharePoint Timer Service when you make changes since it keeps a chached version of you assemblis. Also remember to change the guids and Publickeytoken if you copy this.

And if it doesnt work? don’t blame me cause Im a noob :D

Visual studio: Get Public Key Token

In Visual Studio, go to the Tools menu and click the External Tools menu item. replicate the following settings shown in the picture below.

Then just choose tools -> Get SN token and the result is shown in the Output Window in Visual studion.

Twitter API and LinQ to XmL

Here is a simple C# exampel of how to retrive information from the Twitter API search in atom format.

Create  a class to host the properties in a tweet.

 

class Tweet

{

public string Id { get; set; }

public DateTime Published { get; set; }

public string Link { get; set; }

public string Title { get; set; }

public string Author { get; set; }

public string Uri { get; set; }

}
 

  

 To load the twitter search in atom format use the folling code:

XDocument feed = XDocument.Load(http://search.twitter.com/search.atom?q=sharepoint); 

  

A method to parse the xml data using LinQ to XmL, and return it as a List<Tweet>.

XNamespace atomNS = "http://www.w3.org/2005/Atom";  

           m_tweets = (from tweet in feed.Descendants(atomNS + "entry") 

                 select new Tweet 

                        { 

                            Title = (string)tweet.Element(atomNS + "title"), 

                             Published = DateTime.Parse((string)tweet.Element(atomNS + "published")), 

                             Id = (string)tweet.Element(atomNS + "id"), 

                             Link = tweet.Elements(atomNS + "link") 

                                 .Where(link =&gt; (string)link.Attribute("rel") == "alternate") 

                                 .Select(link =&gt; (string)link.Attribute("href")) 

                                 .First(), 

                             Author = (string)tweet.Element(atomNS + "author").Element(atomNS + "name"), 

                             Uri = (string)tweet.Element(atomNS + "author").Element(atomNS + "uri"),  

                        }).ToList&lt;Tweet&gt;(); 

   

then its just to bind the List<Tweet> as a datasource to eg. a DataGridView or what ever suits your need.

Determine Sharepoint 2007 version

http://insomniacgeek.com/blog/how-to-determine-the-installed-sharepoint-version/

Display “!NEW” tag in a Content Query WebPart

1 - Add this line to the root style sheet element
<xsl:stylesheet xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"

2 - Add this part below
<xsl:template name="TitleOnly" match="Row[@Style='TitleOnly']" mode="itemstyle">
<element match="Row[@Style='TitleWithNewImageOnly']" mode="itemstyle">
name="OuterTemplate.CallPresenceStatusIconTemplate"/>
title="{@LinkToolTip}">
Found this @ http://www.eggheadcafe.com/software/aspnet/29478745/how-to-display-new-tag.aspx

WSS 3.0 Säkerhetskopia och Återställning (SWE)

Det finns tre sätt att göra en säkerhetskopia av samt återställa Microsoft SharePoint Service 3.0. En säkerhetskopia innehåller applikationens Innehåll, Konfiguration och Sök.

  1. Använda sig av Stsadm.exe
  2. Använda sig av Central Administration v3
  3. Använda sig av SQL Server Management Studio

1. Stsadm.exe

För att använda sig av Stsadm.exe vid skapande av säkerhetskopia och återställning krävs det att du är medlem i Administrationsgruppen på servern. Med stsadm kan man även titta på historik  samt status för säkerhetskopiering och återställning.

För mer information om Stsadm.exe gå till: http://technet.microsoft.com/en-us/library/cc288541.aspx

2. Central Administration v3

Du kan även göra en säkerhetskopia och återställning genom Central Administration v3 användargränsnittet. Du kan säkerhetskopiera serverfarmen, webbapplikationen och någon utav eller samtliga innehållsdatabaser i din farm.

För mer information gå till: http://technet.microsoft.com/en-us/library/cc288343.aspx

3. SQL Server Management Studio

Det finns tre olika säkerhetskopior som går att skapa genom SQL Server Mangement Studio.

Full: Skapar en komplett backup av databasen, Det rekommenderas att köra en ”Full” säkerhetskopia första gången man ska göra en säkerhetskopia.

Differential: Skapar en säkerhetskopia på de ändringar som gjorts sedan den senast skapade säkhertskopian.

Transaction Log: Gör det möjligt att återställa databasen till en specifik tid.

För mer information gå till: http://technet.microsoft.com/en-us/library/cc288402.aspx

 

Att tänka på:

Man kan inte använda sig av  Windows SharePoint Services 3.0 för att återskapa Konfigurationsdatabasen samt Central Administration Innehållsdatabasen. Man kan inte använda sig av SQL server 2005 backup för att göra en säkerhetskopia och sedan återskapa den till en annan farm.

När vi skapat en säkerhetskopia av farmen skapas en logfil vid namn Spbackup.txt