Explaning Workflows:
A WF program is a composite activity that contains child activities. The WF program’s child activities can also be composite activities with children of their own and so on. Therefore, a WF program is really nothing more than a composition of activities with a hierarchical treelike structure.
The WF programming model provides support for creating two different styles of WF programs. The first style is a Sequential Workflow program that typically has several predicable paths of execution that can be modeled in the form of a flowchart. When you create a sequential WF program to model a business process, you can commonly use composite activities such as While, IfElse, and Replicator to design the control of flow and achieve the conditional branching required.
The Second type of Workflow is State machine workflows. In real-world scenarios, certain types of business processes are difficult to model using a flowchart.These processes may have many possible paths of execution. A state machine WF program models the different states that a business process goes through on its way toward completion.
The WF programming model provides a base class of each type of WF program. The SequentialWorkflowActivity class is used to create sequential WF programs, while the StateMachineWorkflowActivity class is used to create state machine WF programs.
Both of these classes inherit from CompositeActivity and enable you to create a derived class that serves as the root activity in a WF program.
For More see ....
Getting Started With Workflow Development
Thursday, February 28, 2008
Introduction To Types of Workflow
Tuesday, February 26, 2008
Using RunWithElevatedPrivileges
I have moved this Post to my new blog which includes n example as well. Please click below.
Impersonation in Sharepoint (RunWithElevatedPrivileges)
Sunday, February 24, 2008
Creating Sequential Workflow
Some of the examples of Creating Sequential workflows can be found at following links:
http://www.devx.com/webdev/Article/34032/0/page/1
http://blah.winsmarts.com/2007-8-SharePoint_2007_Workflows_-_Setting_up_your_environment.aspx
http://weblog.vb-tech.com/nick/archive/2007/02/25/2207.aspx
Thursday, February 21, 2008
Look For Users in Active directory,in Sharepoint
The Post has been moved to my new Blog
Check SharePoint Current loggedin user in Active directory
Sharepoint Interview Questions
This Post has been moved to my new blog where you can find Basic and advanced SharePoint developer and administrator interview questions.
SharePoint Interview Questions (Part 1, Part 2, Part 3)
SharePoint Interview questions
SharePoint Developer Interview Questions (Part 1, Part 2, Part 3, Part 4)
Advanced SharePoint Developer nterview Questions
All SharePoint Interview Questions -
SharePoint 2007 and SharePoint 2010 Interview Questions
Wednesday, February 20, 2008
Using SPQuery with Yes/No Columns
To use Yes/No fields with SPQuery,You need to keep in mind some important things.
When you want to query the value for Yes/NO fields in SPQuery,
1. Use value type \"bit\" Not \"Text\
Note: Value type Text work fine with Yes/NO columns in MOSS 2007 but not in WSS.
So, If you are using WSS then you need to use bit not text.
Its always better to use CAML query builder to build a query, and then copy-paste that in SPQuery object.
To use Yes/No columns
if (Convert.ToBoolean(NewsItem["Publish?"]) == true)
{
}
Tuesday, February 19, 2008
Deploy a WebPart in Sharepoint Site
See Step-by-Step example Here
There are many ways to deploy a Webpart in SharePoint sites.
The easiest method is, when you want to deploy a "Sharepoint Webpart" in a given SharePoint site.
Lets Disscus this easy method:
To Deploy a Sharepoint webpart ,folow the steps below:
1. Create a Sharepoint Webpart Project. The Code for which would look like:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace Web_part1
{
[Guid("ab8354bd-824b-4dfd-a996-4c0324a1bb95")]
public class Web_Part1 : System.Web.UI.WebControls.WebParts.WebPart
{
public Web_Part1()
{
this.ExportMode = WebPartExportMode.All;
}
protected override void Render(HtmlTextWriter writer)
{
writer.Write("Hi, This a test for WebPart deployment!");
}
} }
2. Next we will give the Assembly, a Strong name by assigning it a Public key value. To do that Right Click on the project title(in Solution Explorer Window) and go to Properties.
Go to Signing tab, and select a key in dropdown Or you can create a new public key(using sn.exe tool) and then browse it in "signing key file name" field.
3. Now go to Debug tab and select "Start browser with Url" option and write the url of the Sharepoint site, where you want to deploy the Webpart.
4. And now you are all set, Just right click on the project in Solution Explorer again and click deploy.
5. Open the sharepoint site and add a new WebPart page(Site Settings->WebPart pages). ADD a your Webpart into the site and you would see the message "Hi, This a test for WebPart deployment!"
See Step-by-Step example Here
Friday, February 15, 2008
A Tip for Writing SPQuery
To Use a SPQuery for getting the desired List data, We use Sharepoint's SPQuery class.
Some Important Notes about Using SPQuery.
* Use the Column Names that were kept Orignally when the Colum was made for the first time.(Not the ones that you see on column header,they may be same as they were kept earlier or may be not).
For eg, If you created a column with name "BName" and you changed the name(rename) to "BusinessName" later. You will have to use" BName" in SPQuery for getting the BusinessName column data Not "BusinessName".
More on SPQuery:
http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.spquery.aspx
Thursday, February 14, 2008
SharePoint Interview Questions
Please see the Post on my New Blog Here . It has some more Questions.
Add "RichTextBox" in SharePoint WebPart and ASP.Net User Control
Today I had to add a "RichTextBox" in the Sharepoint Web Part,but AS there is no such control in ASP.Net, I was a little worried!.But After "google-ing" for some time,I stoped at a Sharepoint Control named "InputFormTextBox". Using a property named "RichText",this control can behave like an Extended Rich text box of Sharepoint.
InputFormTextBox is a class in "Microsoft.SharePoint.WebControls" namespace.So we will Use its Multiline,RichText and TextMode properties to make it a RichTextBox.
To Use This control in a Sharepoint Webpart Project we Use:
InputFormTextBox _txt = new InputFormTextBox();
The Code below for adding it into Webpart goes below:
using System;using System.Security;
using System.Net;
using System.Collections.Generic;
using System.Text;using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
[assembly:AllowPartiallyTrustedCallers]
namespace TestRichTextBox{
public class TestRTB : WebPart
{
Button _btn = new Button();
InputFormTextBox _txt = new InputFormTextBox();
}
protected override void CreateChildControls()
{
try{
_txt.TextMode = TextBoxMode.MultiLine;
_txt.Rows = 10;_txt.RichText = true;
_txt.RichTextMode = SPRichTextMode.FullHtml;
this.Controls.Add(_txt);
_btn.Text = "Click me";
_btn.Click += new EventHandler(_btn_Click);
this.Controls.Add(_btn);
}
catch (Exception _ex)
{
Page.Response.Write(_ex.ToString());
}
}
void _btn_Click(object sender, EventArgs e)
{
Page.Response.Write(_txt.Text);
}
protected override void Render(HtmlTextWriter writer)
{
RenderChildren(writer);
}
}
}
Scince I was using ASP.NET User Control and was handlling all the events in it. I needed to add this Control in my ASP.Net .ascx file.(USer Control file).
SO I planned, TO add this InputFomTextBox Control in my WebApplication toolbox.So that i can easily drag and drop it in my form.
To Use InputTextbox Control in ASP.Net User Control follow the Steps Below:
To Get Started:
1. Add Reference to Microsoft.Sharepoint.dll using Add reference option.
Now, To add Sharepoint control in your design tool
-> Right Click on design tool to add new tab.
->Name it as "Sharepoint Tools" and OK.
-> Now right click on the tab and click "Choose Items"
-> Under .Net Framework Components select "InputformTextBox" and click ok
Now drag and Drop the tool in your User control/ASP.Net WebApplication
Note: You may find that ASP.Net Automatically Registers the assembly with the strong name on the top of ascx page, when you add the control in toolbox tab.
You Can aslo Use lots of other Sharepoint Controls like Datetime control an checkbox controls and other.
References for this article :
http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.inputformtextbox.aspx
Wednesday, February 13, 2008
Introduction to SharePoint Object Model
I have moved this post to my new blog. Please click SharePoint 2007 Object modelto see the Post.
You can also check SharePoint 2010 Object model at
SharePoint 2010 Object Model
Monday, February 11, 2008
Getting Started With Workflows:
I have moved this Post to my New blog. Please Click at the below link
Getting Started With Workflows
Sunday, February 10, 2008
Programmatically Adding Documnets in Document Library
Brief:
By Creating a ASP.Net file uploload contol and a submit button. You can add documents and Files from your local folder,directly into Sharepoint Document library by using SPFile class.
Lets get Started:
1. Create a ASP.Net Webapplication , and Add a Fileupload Control in that.
2. Add a button named "Upload" under the Fileupload Control.
3. Now double click the Upload Button and write the Site collection and site reference as below.
4. And Finally, Call the DocumnetsAttached method on the submit click.
protected void Button1_Click(object sender, EventArgs e)
{
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.OpenWeb();
DocumnetsAttached(myWeb);
}
Make sure you add a reference to Microsoft.Sharepoint.dll.
//The Function for uploading a File in a Document Library is Below:
public void DocumnetsAttached(SPWeb site)
{
if (FileUpload1.HasFile)
{
SPFolder folder = site.GetFolder("Document_Library_Name");
SPFileCollection files = folder.Files;
Stream fStream = FileUpload1.PostedFile.InputStream; //path of the file to upload
byte[] contents = new byte[fStream.Length];
fstream.position =0;
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
string Filename = FileUpload1.FileName;
string URL = SPContext.Current.Site.Url + "/Document_Library_Name/" + Filename;
SPFile currentFile = files.Add(URL, contents);
}
}
POpulating a Drop-Down with List Data
Steps:
1. Create a Drop-Down control,in a Webpart or Webapplication.
2. On the Load method, Add the following code.
protected override void OnLoad(EventArgs e)
{
if (!Page.IsPostBack)
{
DataSet ds = new DataSet();
SPSite mySite = SPContext.Current.Site;
SPWeb myWeb = mySite.OpenWeb();
SPList list = myWeb.Lists["ListName"];
DataTable DTable_List = list.Items.GetDataTable();
DTable_List.TableName = "Table1";
ds.Tables.Add(DTable_List);
DropDownBGroup.DataSource = ds.Tables["Table1"];
DropDownBGroup.DataTextField = "FieldName";
DropDownBGroup.DataValueField = "FieldName";
DropDownBGroup.DataBind();
DropDownBGroup.SelectedIndex = 0;}
base.OnLoad(e);
}
}
Sunday, February 3, 2008
Create Web Part for Sharepoint With User Control
Brief:
To Create a Web Part for sharepoint sites, Create a User control in Visual studio(handling all the events). Drag it into a sharepoint Webpart application(project). And Finally, Deploy the webpart into sharepoint site.
Steps are:
1. Create a blank web application and add a web user control (name WebUserControl1.ascx) into it.
2. Add one TextField and a Button to the user control. The ids of these controls are TextBox1 and Button1 respectively.
3. Add a button1_click even in codebehind file of WebUserControl1 , i.e. WebUserControl1.cs
Like:
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "I am in Web part -> In user control ";
}
3. Now copy this user control to a new folder,name it "controls".The folder should be placed under your (Web Application)
path.eg: “C:\Inetpub\wwwroot\wss\VirtualDirectories\80\controls\”.
4. Create a New Web part application using Visual Studio SharePoint Web Part template.
And The code in Web part application goes below:
using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
namespace WepPart_Usercontrol
{
[Guid("68dd6b12-7b2d-4dc8-941f-80acbf83f16f")]
public class WepPart_Usercontrol : System.Web.UI.WebControls.WebParts.WebPart
{
UserControl userControl;
public WepPart_Usercontrol()
{
this.ExportMode = WebPartExportMode.All;
}
protected override void Render(HtmlTextWriter writer)
{
userControl.RenderControl(writer);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
userControl = (UserControl)Page.LoadControl(@"/controls/WebUserControl1.ascx");
Controls.Add(userControl);
}
}
}
