Thursday, August 20, 2009

Finding the failed feature-id in MOSS 2007

List featIDs = new List();
foreach (SPFeatureDefinition featdef in SPFarm.Local.FeatureDefinitions)
{
try
{
//db5c27c4-6f17-4296-bc05-bbe9978284b4
if (featdef.DisplayName.Contains("manoj"))
{
Console.WriteLine("{0}: {1}", featdef.Id, featdef.DisplayName);
break;
}
}
catch
{
//This code will be executed if the feature does not have the manifest file.
Console.WriteLine("################################################");
Console.WriteLine("Error Ocurrred! Attempting to get feature ID of the feature without manifest file...:");
Console.WriteLine(featdef.Id.ToString());
}

Friday, August 14, 2009

Content Types and Workflows

  • Workflows can be associated with content Type
  • Workflow tasks are special content type(0x010801)
  • Content types can have special new, display and edit forms.
  • Therfore, the task edit page for a workflow task can be customized
  • Thursday, August 6, 2009

    Finding MAC address in VB.Net

    Imports System.Management
    Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim mc As System.Management.ManagementClass
    Dim mo As ManagementObject
    mc = New ManagementClass("Win32_NetworkAdapterConfiguration")
    Dim moc As ManagementObjectCollection = mc.GetInstances()
    For Each mo In moc
    If mo.Item("IPEnabled") = True Then
    ListBox1.Items.Add("MAC address " & mo.Item("MacAddress").ToString())
    End If
    Next
    End Sub
    End Class

    Tuesday, July 28, 2009

    Data Import to a Sharepoint List

    Example:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using Microsoft.SharePoint;
    namespace DataImport
    {
    class Program
    {
    static void Main(string[] args)
    {
    // Check there are enough command line parameters
    if (args.Length <>[ []]");
    return;
    } char[] splitArray = { ',' };
    int startRecord = 0;
    int endRecord = int.MaxValue;
    // Store the command line parameters.
    string paramFileName = args[0];
    string paramWeb = args[1];
    string paramList = args[2];
    // Get start record integer.
    if (args.Length > 3)
    {
    if (args[3] != String.Empty)
    {
    startRecord = Convert.ToInt32(args[3]);
    }
    // Get end record integer.
    if (args.Length > 4)
    {
    if (args[4] != String.Empty)
    { endRecord = Convert.ToInt32(args[4]);
    }
    }
    }
    // validate the start and end record
    if (endRecord < startRecord)
    {
    Console.WriteLine("End record parameter must be greater than start record parameter");
    return;
    }
    // open the CSV file for reading
    using (StreamReader fileRdr = File.OpenText(paramFileName))
    {
    // connect to the site collection
    using (SPSite spSite = new SPSite(paramWeb))
    {
    // open the root site
    using (SPWeb spWeb = spSite.OpenWeb())
    {
    // get the list from the site
    SPList spList = spWeb.Lists[paramList];
    // read the fields in the header
    string line = fileRdr.ReadLine();
    string[] fieldNames = line.Split(splitArray);
    // get an array of field from the list
    // this assumes the field names match
    // we need the field Id when inserting rows
    SPField[] spFields = new SPField[fieldNames.Length];
    for (int looper = 0; looper < fieldNames.Length; looper++)
    {
    string strName = fieldNames[looper];
    SPField field = spList.Fields.GetField(strName);
    spFields[looper] = field;
    }
    // get the next line
    line = fileRdr.ReadLine();
    // start counting from the 2nd line
    int lineCount = 0;
    // keep reading till we run out of file
    while (!fileRdr.EndOfStream)
    { // if we are past or on the start record then
    if (lineCount >= startRecord)
    { // a little bit of progress
    if (lineCount % 10 == 0)
    Console.Write(".");
    // get the values from the line
    string[] fieldValues = line.Split(splitArray);
    // create a new list item
    SPListItem newItem = spList.Items.Add();
    // populate the values in the item using the
    // SPFields we created earlier
    for (int looper = 0; looper < fieldValues.Length; looper++)
    {
    newItem[spFields[looper].Id] = fieldValues[looper];
    }
    // update the item to the list
    newItem.Update();
    }
    // see if we want to stop prematurely
    if (lineCount >= endRecord) break;
    lineCount++;
    //read the next line
    line = fileRdr.ReadLine();
    if (fileRdr.EndOfStream)
    { string[] fieldValues = line.Split(splitArray);
    // create a new list item
    SPListItem newItem = spList.Items.Add();
    // populate the values in the item using the
    // SPFields we created earlier
    for (int looper = 0; looper < fieldValues.Length; looper++)
    {
    newItem[spFields[looper].Id] = fieldValues[looper];
    }
    // update the item to the list
    newItem.Update();
    }
    }
    }
    }
    }
    }
    }
    }

    Monday, July 27, 2009

    Where to use WSS Object Model

    Object Models - Sharepoint

    Windows SharePoint Servies 3.0Microsoft Office SharePoint Server 2007
    Microsoft.SharePoint.dllMicrosoft.Office.Server.dll
    Microsoft.Office.Server.Publishing.dll
    Microsoft.Office.Server.Policy.dll
    Microsoft.Office.Server.Search.dll
    Microsoft.SharePoint.Portal.dll
    Microsoft.Office.Workflow.Tasks.dll
    Microsoft.SharePoint.Publishing.dll
    Microsoft.Sharepoint.Workflow.Actions.dll

    Document Libraries in Sharepoint

    WSS Document Library is a special list type
  • Provides support for uploading/storing documents.
  • provides support for document versioning
  • Document data is stored in Microsoft SQL server content Database
  • Like a list with one(and only one)attachment
  • Document Library has a document template
  • Document template used when user clicks New command
  • User Content Types for multiple document templates
  • Sharepoint Lists

    List types designed to store content in form of items
  • Each list type defines schema including set of columns
  • List type includes Form pages(eg.,AllItems.aspx)
  • List type can have multiple views
  • Creating a List instance from a List type
  • Create list items using WSS built-in List Types.
  • Create List items from Custom Lists and define columns
  • Users can Add/Remove/modify columns on list instance.
  • List can contain Content Types
  • Content Types contain their own fields,workflows, and forms
  • Content Type fields are automatically added to a list when the Content Type is associated with it
  • Creating a Sharepoint Theme

    1. Copy and rename the existing theme.
    2. Rename the info file of the theme with the given name of the copied folder.
    3. Open the .inf file and replace the titles.
    4. Customize colors, fonts and so on in the style sheets of the theme.
    5. Add your own images to the theme.
    6. Create a thumbnail and copy it to the 12\TEMPLATE\Images folder.
    7. Add theme definition in the SPTHEMES.xml in the 12\TEMPLATE\Layouts\ folder.

    SharePoint List Template Id’s

    When creating SharePoint 2007 receivers, the ListTemplateId attribute is associated with a “value” that is an optional unique identifier for the target template for which the receiver is being built. The value of templates are as shown below.
    ValueDescription
    1200Administrator tasks list
    104Announcements list
    303Blog Categories list
    302Blog Comments list
    301Blog Posts list
    105Contacts list
    120Custom grid for a list
    118Custom Workflow Process
    130Data Connection library
    110Data sources
    108Discussion board
    101Document libraryaEvents list
    150Gantt Tasks list
    100Generic list
    1100Issue tracking
    103Links list
    114List template gallery
    116Master pages gallery
    201Meeting Agenda list
    202Meeting Attendees list
    204Meeting Decisions list
    207Meeting Objectives list
    200Meeting Series list
    210Meeting text box
    211Meeting Things To Bring list
    212Meeting Workspace Pages list
    117No-Code Workflows
    2002Personal document library
    109Picture library
    300Portal Sites list
    2003Private document library
    111Site template gallery
    102Survey
    107Tasks list
    112User Information list
    113Web Part gallery
    119Wiki Page library
    140Workflow History
    115XML Form library

    Friday, July 24, 2009

    Introducing Master Pages in Sharepoint

    * Central file controlling the layout and design of the content pages in a sharepoint site
    • Title, logo and description of the site
    • Navigation controls
    • Welcome and Administration
    • Search experience
    • Linking cascading style sheet(CSS) files and script files
    • Web part Manager
    • Contentplaceholders for sharepoint products and technologies

    Setting Master pages programatically

    • Execute code to switch to new provisioned Master page
    • Feature Receiver

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
    SPWeb site = Properties.Feature.Parent as SPWeb;
    Site.Properties["OriginalMasterPage"] = site.MasterUrl;
    site.Properties.Update();
    site.MasterUrl="/_catalogs/masterpage/Litware.master";
    site.Update();
    }

    CSS Files

  • CSSLink control loads core.css file
  • Override Styles
  • with an Explicit embedded <style> element
  • programitically setting the AlternateCSSUrl property of the SPWeb
    Public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
    SPWeb site = properties.Feature.parent as SPWeb;
    site.AlternateCSSUrl="/_layouts/LitwareCSS/LitwareCore.css";
    site.Update();
    }

    Thursday, July 23, 2009

    Singleton Pattern

    Using System;
    Using System.Text;
    Namespace Singletonproject
    Class Singleton
    {
    Private Datetime CreatedDateTime;
    Private Singleton
    {
    CreatedDateTime = System.DateTime.Now;
    }
    Private static Singleton instancia = null;
    Private Object Padlock = new object();
    Public Singleton Instancia
    {
    get{
    if(instancia==null)
    instancia= new Singleton();
    return instancia;
    }
    }
    Public string GetDateTime
    {
    return CreatedDateTime.Tostring();
    }
    Calling procedure
    Singletonproject.Singleton clsc= Singletonproject.Singleton.Instancia;
    Label1.text = clsc.GetDateTime.Tostring();

    Finding the Id (Guid) for a SharePoint List

    * Navigate to the SharePoint list using the browser.
    * Select the Settings + List Settings menu command.
    Copy the Url from the browser address bar into Notepad. It will look something like: http://moss2007/ProjectX/_layouts/listedit.aspx?List=%7B26534EF9%2DAB3A%2D46E0%2DAE56%2DEFF168BE562F%7D
    Delete everying before and including “List=”.
    Change “%7B” to “{”
    Change all “%2D” to “-“
    Chnage “%7D” to “}”
    You are now left with the Id:
    {26534EF9-AB3A-46E0-AE56-EFF168BE562F}

    Thursday, July 16, 2009

    LINQ

    C# 3.0 includes many strong new features, but one of the most interesting is the inclusion of its new query keywords, that you use to create Query Expressions. Query Expressions are most commonly associated with Language Integrated Query (LINQ). They're the core syntax that you'll use when you create LINQ queries, whether you use LINQ to Objects, LINQ to SQL, LINQ to XML, or some other custom LINQ provider. I'll discuss the query keywords, how those keywords map to methods defined using the query operands, and how you can define your own custom implementation for the query keywords. The C# team worked to minimize the necessary grammar for LINQ and the associated query syntax. They ended up adding eight contextual keywords to the C# language specifically for query: from, where, select, group, into, orderby, join, and let.

    int[] someNumbers = { 2, 3, 7, 11, 13, 17, 19 };
    var query = from number in someNumbers

    someNumbers is the datasource, and number is the range variable. The datasource must implement IEnumerable, or IEnumerable. In this example, someNumbers implements IEnumerable. The compiler gives the range variable a type to match the type enumerated by the datasource. In the example above, number will be an integer. In general, the range variable is of type T, whenever the datasource implements IEnumerable. In the case where the range variable implements IEnumerable, the range variable is a System.Object. You never need to declare the type of the range variable; the compiler infers it. Consider you have the following string array
    string[] names = { "Burke", "Connor", "Frank", "Everett", "Albert", "George", "Harris", "David" };
    Task is to take the name which has length greater than 5 and make them capital letter. if we go in normal way we will put a for loop and then call it and assign a temp variable fetch it out hmmm lot of steps lets see how LINQ works on this

    LINQ syntax
    var query = from s in names where s.Length == 5 select s.ToUpper();

    simple rite it looks like T-SQL but in the reverse way don't confused. in T-SQL you know that you are going to query either a table or view but in LINQ you are going to query a object so you dont know from where you are going to query to from comes first instead of select

    Friday, May 8, 2009

    Explicit cursors in PL/SQL procedures

    /* Use of Explicit cursor in procedures is shown in the below example. */ Create or replace procedure SP_EMP is
    cursor Emp_cur is select empno,ename from EMP;
    Emp_cur_var emp_cur%RowType;
    begin
    open Emp_cur;
    loop
    Fetch Emp_cur into Emp_cur_var;
    exit when Emp_cur%NotFound;
    dbms_output.put_line(Emp_cur_var.empno' ' Emp_cur_var.ename);
    endloop;
    close Emp_cur;
    end SP_EMP;

    Thursday, April 9, 2009

    AJAX

    Stands for “Asynchronous JavaScript and XML” Development technique for creating interactive web applications Not a technology, just a methodology. Allows to kick off an HTTP request in background Callbacks kick back into JavaScript Code Supported in all standard browsers.

    A is for “asynchronous” – requests (asynchronously or synchronously) – web page to be updated without refreshing – parallel requests – using asynchronous

    J is for “JavaScript” – used on the client-side (in the browser) – can use server side languages that accept HTTP requests   & return HTTP responses

    X is for “XML” – request & response contains XML – contain any text (single text value, delimited text, …)