Sunday, August 1, 2010

Sharepoint Object Model

  • SPFARM-gets a collection representing all servers in the farm 
  • SPServer-represents a physical server computer 
  • SPWebApplication-Sites property and ContentDatabases property 
  • SPSiteCollection-represents the collection of site collection within the web application 
  • SPSite-represents a set of logically related SPWeb objects. Has members to manage the site collection. OpenWeb() returns Website.
  • SPWeb- Has members to manage a site, such as template, themes, files and folders. 
  • SPList-  Manage the List and its items. 
  • SPField- has members that contains settings of the field. 
  • SPListItem- represents single row in the List.

Types of Sharepoint Sites

  1. Team Site
  2. Blog
  3. Collaboration Portal
  4. Publishing Portal
  5. Report Center
  6. Records Center
  7. Search Center

Monday, December 21, 2009

Simlest way to apply dynamic themes and skins

Introduction

It is very easy to make dynamic themes in ASP NET 2.0. In this Article I will tell you how to apply dynamic themes in C# .

Background

I was getting problem to apply dynamic themes by using session and query string methods and there I have to redirect my page again to get the desired themes. To solve this problem I have used Form to make it in simple way.

What are themes

I have not written following my own got definition from somewhere on the internet I liked it so I have added. Themes are introduced in ASP.NET 2.0 to counter the troubles faced by developers to define the layout of server controls and make them look coherent to the overall application, with minimum possible efforts. Default or Global themes are contained in a special folder inside the framework and can be declared in the source as well as class files. However, custom made themes can also be saved inside the predefined "App_Themes" folder inside ASP.NET applications, making them easier to manage and interpolate according to your needs. The essential part of themes are skin files with .skin extension. Besides skin files, a theme can be composed of styles sheets .css files as well as images for added support for the layout of the website.

Step1:

1. Add App_Themes Folder.

2. Add Themes in App_Themes lets keep its name as Theme1.

2. Add Skin File in Theme1 Folder


3. Add skinid for each skin.
      

    

Step2:



  1. Add Skin File in Theme2 Folder


  2. Add skinid for each skin 

How to apply themes 

Themes can be applied only on  PreInit or earlier events. Add All themes in dropdownlist. Get the selected Themes on Request.Form.

protected void page_PreInit(object Sender, EventArgs e)
    {      

        string strTheme = Request.Form["DropDownList1"];    
        if (strTheme == null)
        {
         strTheme= "Theme1";
         Page.Theme = strTheme;
        }
        else
        {
            Page.Theme = strTheme;
        }        
       
    }

protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            DropDownList1.Items.Add("Theme1");
            DropDownList1.Items.Add("Theme2");
        }

    }  


Monday, December 29, 2008

Execl to Folder ceation in file handling

Hi Gagan,
In this post I will explain how to create folder if we we have already name of folder in our Excel file.
Here I have Excel

I need to create folder as mentioned in its first column

In C#.net we need to create Oledb connectioon to access data from Excel.
I have given Sample code you can understand easily by it

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.OleDb;

using System.IO;

namespace xlsToFolder

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @"D:\c3.xls" + ";Extended Properties=Excel 8.0");

con.Open();

try

{

DataSet myDataSet = new DataSet();

OleDbDataAdapter myCommand = new OleDbDataAdapter(" SELECT * FROM [" + "Sheet1" + "$]", con);

myCommand.Fill(myDataSet);

con.Close();

//MessageBox.Show(myCommand.ToString());

// textBox1.AppendText("\nDataSet Filled");

//Travers through each row in the dataset

foreach (DataRow myDataRow in myDataSet.Tables[0].Rows)

{

//Stores info in Datarow into an array

Object[] cells = myDataRow.ItemArray;

//Traverse through each array and put into object cellContent as type Object

//Using Object as for some reason the Dataset reads some blank value which

//causes a hissy fit when trying to read. By using object I can convert to

//String at a later point.

foreach (object cellContent in cells)

{

//Convert object cellContect into String to read whilst replacing Line Breaks with a defined character

string cellText = cellContent.ToString();


//It will create the folder under folder named Test4 System.IO.Directory.CreateDirectory("c:/Test4/" + cellText);

}

}

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

finally

{

con.Close();

}

}

}

}






Read XML in C#.net

We can use File object to read XML file but we mostly use XML parsing.

.NET provides five namespace to support XML classes.
  1. System.Xml;
  2. .Xml.Schema;
  3. .Xml.Serialization;
  4. .Xml.XPath;
  5. .Xml.Xsl;
The System.Xml namespace contains major XML classes.

The XmlReader class is an abstract bases classes and contains methods and properties to read a document.
The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. As their name explains, they are used to read text, node, and schemas.
The XmlWrite class contains functionality to write data to XML documents.
XmlNode class represents a single node of XML but that could be the root node of an XML document and could represent the entire file. Three major classes derived from XmlNode are XmlDocument, XmlDataDocument and XmlDocumentFragment. XmlDocument class represents an XML document and provides methods and properties to load and save a document. It also provides functionality to add XML items such as attributes, comments, spaces, elements, and new nodes. The Load and LoadXml methods can be used to load XML documents and Save method to save a document respectively.

Reading XML Documents

XmlTextReader xmlReader = new XmlTextReader("D:\\test.xml");

The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. Besides XmlReader methods and properties, these classes also contain members to read text, node, and schemas respectively. I am using XmlTextReader class to read an XML file. You read a file by passing file name as a parameter in constructor.

XmlTextReader xmlReader = new XmlTextReader("D:\\test.xml");

Then call read() method

xmlReader.read();


using System;

using System.Xml;

namespace ReadXml

{

class Class1

{

static void Main(string[] args)

{

// Create an isntance of XmlXmlReader and call Read method to read the file

XmlXmlReader xmlReader = new XmlXmlReader("D:\\test.xml");

xmlReader.Read();

// If the node has value

while (xmlReader.Read())

{

// Move to fist element

xmlReader.MoveToElement();

Console.WriteLine("XmlXmlReader Properties Test");

Console.WriteLine("===================");

// Read this element's properties and display them

Console.WriteLine("Name:" + xmlReader.Name);

Console.WriteLine("Base URI:" + xmlReader.BaseURI);

Console.WriteLine("Local Name:" + xmlReader.LocalName);

Console.WriteLine("Attribute Count:" + xmlReader.AttributeCount.ToString());

Console.WriteLine("Depth:" + xmlReader.Depth.ToString());

Console.WriteLine("Line Number:" + xmlReader.LineNumber.ToString());

Console.WriteLine("Node Type:" + xmlReader.NodeType.ToString());

Console.WriteLine("Attribute Count:" + xmlReader.Value.ToString());

}

}

}

}




Writing XML Documents

XmlTextWriter textWriter = new XmlTextWriter("D:\\testWrite.xml", null) ;



using System;

using System.Xml;

namespace ReadingXML2

{

class Class1

{

static void Main(string[] args)

{

// Create a new file in C:\\ dir

XmlTextWriter textWriter = new XmlTextWriter("D:\\testWrite.xml", null);

// Opens the document

textWriter.WriteStartDocument();

// Write comments

textWriter.WriteComment("First Comment XmlTextWriter Sample Example");

textWriter.WriteComment("myXmlFile.xml in root dir");

// Write first element

textWriter.WriteStartElement("Student");

textWriter.WriteStartElement("r", "RECORD", "urn:record");

// Write next element

textWriter.WriteStartElement("Name", "");

textWriter.WriteString("Student");

textWriter.WriteEndElement();

// Write one more element

textWriter.WriteStartElement("Address", ""); textWriter.WriteString("Colony");

textWriter.WriteEndElement();

// WriteChars

char[] ch = new char[3];

ch[0] = 'a';

ch[1] = 'r';

ch[2] = 'c';

textWriter.WriteStartElement("Char");

textWriter.WriteChars(ch, 0, ch.Length);

textWriter.WriteEndElement();

// Ends the document.

textWriter.WriteEndDocument();

// close writer

textWriter.Close();

}

}

}