Thursday, 29 December 2011
Wednesday, 28 December 2011
hello world webpart
: Coding for Hello world Web Part
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace helloworld.helloworldwebpart
{
[ToolboxItemAttribute(false)]
public class helloworldwebpart : WebPart
{
protected override void CreateChildControls()
{
base.CreateChildControls();
this.Controls.Add(new LiteralControl("<html><body>"));
this.Controls.Add(new LiteralControl("<h1 style='font-size: large; color: #0000FF; text-align: center; text-decoration: blink'>Hello, world! Welcome to Sharepoint world</h1>"));
this.Controls.Add(new LiteralControl("</body></html>"));
}
}
}
coding for iterating web,list and libraries
Coding for Iterating the Web, lists and libraries
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
namespace basicserverobjectmodelexample
{
class Program
{
static void Main(string[] args)
{
som();
Console.Read();
}
/// <summary>
/// iterating root web, lists, libraries
/// </summary>
public static void som()
{
using (SPSite osite = new SPSite("http://igrid103:1990"))
{
using (SPWeb oweb = osite.RootWeb)
{
Console.WriteLine("********************");
Console.WriteLine("\n");
Console.WriteLine("Web");
Console.WriteLine("\n");
Console.WriteLine(oweb.Title);
Console.WriteLine("********************");
SPListCollection ocoll = oweb.Lists;
Console.WriteLine("********************");
Console.WriteLine("\n");
Console.WriteLine("lists");
Console.WriteLine("\n");
foreach (SPList olist in ocoll)
{
if (olist.BaseTemplate ==SPListTemplateType.GenericList)
{
Console.WriteLine(olist.Title);
}
}
Console.WriteLine("********************");
Console.WriteLine("********************");
Console.WriteLine("\n");
Console.WriteLine("library");
Console.WriteLine("\n");
foreach (SPList olist in ocoll)
{
if (olist.BaseTemplate ==SPListTemplateType.DocumentLibrary)
{
Console.WriteLine(olist.Title);
}
}
Console.WriteLine("********************");
}
}
}
}
}
manipulating termstore using visual webpart
SharePoint 2010 -Manipulating Term Store using Visual Web Part
Summary of Steps
Step 1: Create the SharePoint Project. In this step, create a Microsoft Visual Studio 2010 project that you can use to deploy and test your custom action menu.
Step 2: Create a Visual WebPart.in this step create visual web part used for customizing purpose and it can be deployed to the sites.
Step 3: Add user control
Step 4: Coding for manipulating term store using visual webpart
Step 1: Create the SharePoint Project
Open Visual Studio 2010 >File > New >Project >SharePoint 2010>Empty SharePoint Project. >Name it Custom Menu in List Settings>Ok >and select deploy as farm solution>give site name>finish.
Step 2: Create a Visual Web Part
In the solution explorer right click on the solution >add>new item>Visual Web Part>give name for that Visual Web Part>ok
Step 3: Add user control
In the solution explorer click the designing part of the user control like” meta data usercontrol.ascx” writes html coding as like that of below
Step 4: Add references
In the Solution explorer right click on references>add references>select Microsoft. SharePoint, Microsoft.SharePoint.Taxonomy.
Step5: Coding for manipulating term store using visual Web Part
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
namespace termstore.metadata
{
public partial class metadataUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SPSite thisSite = SPContext.Current.Site;
TaxonomySession session = new TaxonomySession(thisSite);
TreeNode treeNode = new TreeNode();
treeNode.Text = "Metadata Awesomeness";
metadatatree.Nodes.Add(treeNode);
foreach (TermStore termStore in session.TermStores)
{
var tsNode = new TreeNode(termStore.Name, null, null, "", null);
treeNode.ChildNodes.Add(tsNode);
//treeNode = tsNode;
foreach (Group group in termStore.Groups)
{
var node = new TreeNode(group.Name, null, null, "", null);
treeNode.ChildNodes.Add(node);
//treeNode = node;
foreach (TermSet termSet in group.TermSets)
{
node = new TreeNode(termSet.Name, null, null, "", null);
treeNode.ChildNodes.Add(node);
treeNode = node;
foreach (Term term in termSet.Terms)
{
AddTermSet(term, treeNode);
}
}
}
}
}
void AddTermSet(Term term, TreeNode treeNode)
{
var node = new TreeNode(term.Name, null, null, "", null);
treeNode.ChildNodes.Add(node);
treeNode = node;
foreach (Term t in term.Terms)
{
AddTermSet(t, treeNode);
}
}
}
}
Result
References
http://www.zimmergren.net/technical/sp-2010-introduction-to-programmatically-working-with-taxonomies-in-sharepoint-server-2010Sunday, 18 December 2011
Export library or list using Power shell
this code for export library
export-spweb -itemurl "/library%20Doc/" -path "D:\libexport.cmp" -identity "http://igrid103:55555"
this code is for export list
export-spweb -itemurl "/Lists/detail/" -path "D:\New folder\libexport.cmp" -identity "http://igrid103:55555"
export-spweb -itemurl "/library%20Doc/" -path "D:\libexport.cmp" -identity "http://igrid103:55555"
this code is for export list
export-spweb -itemurl "/Lists/detail/" -path "D:\New folder\libexport.cmp" -identity "http://igrid103:55555"
Saturday, 17 December 2011
Upload Document Library using Server Object Model
This is the code
using (SPSite siteCollection = new SPSite("http://igrid103:1990"))
{
using (SPWeb spWeb = siteCollection.OpenWeb())
{
SPList spList = spWeb.Lists.TryGetList("Shared Documents");
string fileName = "new resume.doc";
FileStream fileStream = null;
Byte[] fileContent = null;
try
{
string docPath =@"D:\anand raj\"; //physical location of the file
fileStream = File.OpenRead(docPath + fileName);
fileContent = new byte[Convert.ToInt32(fileStream.Length)];
fileStream.Read(fileContent, 0, Convert.ToInt32(fileStream.Length));
spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + fileName, fileContent, true);
spList.Update();
}
catch (Exception ex)
{
}
finally
{
if (fileStream != null)
{
fileStream.Close();
}
}
}
}
using (SPSite siteCollection = new SPSite("http://igrid103:1990"))
{
using (SPWeb spWeb = siteCollection.OpenWeb())
{
SPList spList = spWeb.Lists.TryGetList("Shared Documents");
string fileName = "new resume.doc";
FileStream fileStream = null;
Byte[] fileContent = null;
try
{
string docPath =@"D:\anand raj\"; //physical location of the file
fileStream = File.OpenRead(docPath + fileName);
fileContent = new byte[Convert.ToInt32(fileStream.Length)];
fileStream.Read(fileContent, 0, Convert.ToInt32(fileStream.Length));
spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + fileName, fileContent, true);
spList.Update();
}
catch (Exception ex)
{
}
finally
{
if (fileStream != null)
{
fileStream.Close();
}
}
}
}
Subscribe to:
Comments (Atom)