Monthly Archives: May 2011

Download the Sharepoint List Attachment

You can download the attachment from the any SharePoint List to your local drive in your Server using the following code. Based on the article from Microsoft “How to Pro grammatically Download attachment from list items in WSS” i iterate the list item and also i checked for Exist of attachment for each list item.

Inherited Web-part Class and create the button control and attach the click event, in the “CreateChildControls” method as below code

(Click on above image to Enlarge the Image)

Now write the code to download the attachment from the List as below in the Button Click event Method

(Click on above image to Enlarge the Image)
Now you create a custom web-part for download the attachment of the list. Create Strong key and build the class deploy it in your Server and update the Web.Config. Add it in web-part gallery and edit the page select the web-part to download attachment. that it. When you click on the web-part, it will automatically download all attachment to the specified path.

Programatically copy document from list to library

Using this below code you can copy the document from list to library, with in the same web application. The logic is as below

check the same child window form is already opened

int FlagMultiple=0;
                foreach (Form Objform in Application.OpenForms)
                    if (Objform.Text == "FormText")
                if (FlagMultiple!=1)
                    Form1 objForm = new Form1();
                    objForm.MdiParent = this;
                    objForm.StartPosition = FormStartPosition.CenterScreen;

Stsadm operations

· Activatefeature
Activates a feature in the feature collection.
· Addalternatedomain
Adds an internal URL and maps it to one of the five URL zones of a Web application or external resource.
· Addcontentdb
Creates a new content database or adds a database that needs to be upgraded when the url and databasename parameters are specified.
· Adddataconnectionfile
Adds a new DataConnectionFile to the DataConnectionFiles collection for InfoPath Forms Services.
· Add-ecsfiletrustedlocation
Lets an administrator add a file to the trusted location list.
· Add-ecssafedataprovider
Lets an administrator add a supported provider type to the safe provider list.
· Add-ecstrusteddataconnectionlibrary
Adds a trusted data connection to a library.
· Add-ecsuserdefinedfunction
Adds a user defined function.
· Addexemptuseragent
Adds a user agent, which is typically in the form of a search bot, to receive the XML file that contains the data of the form for indexing instead of the HTML rendering of the form.
· Addpath
Adds a managed path inclusion to a Web application.
· Addpermissionpolicy
Adds a user to a policy role for the Web application based on the specified permission level name and corresponding zone.
· Addsolution
Adds a solution file to the solution store.
· Addtemplate
Adds a site template to the template gallery.
· Adduser
Adds a user account to the specified site collection and assigns it to the specified site group.
· Authentication
Authentication provides the user identity input to the authorization process which determines what actions the current user is allowed to perform on a given object.
· Backup
Describes how to back up a site collection, an individual database, a Web application, or an entire farm.
· Backuphistory
Displays a history of backup and restore operations that have been run.
· Creategroup
Lets site collection administrators create new groups from any site collection.
· Createsite
Creates a site collection at the specified Uniform Resource Locator (URL) with the specified user as site collection owner and site collection administrator.
· Deletecontentdb
Detaches a content database when the Web application, database name, and database server are specified.
· Deleteconfigdb
Unprovisions the local machine from the farm and deletes the configuration database (but does not drop the configuration database).
· Deletegroup
Deletes a group created in Microsoft Office SharePoint Server 2007.
· Deletesite
Deletes the site collection with the specified URL from the Web application.
· Deletesolution
Removes a Windows SharePoint Services Solution Package (*.wsp) from the solution store.
· Deletessp
Deletes a Shared Services Provider (SSP) in a Web application when the title parameter is specified.
· Deletessptimerjob
Deletes all of the timer jobs in the Shared Services Provider (SSP).
· Deletetemplate
Deletes a specified site template from the site template gallery.
· Deleteuser
Deletes a user account from the specified site collection and specified site.
· Deleteweb
Deletes a subsite using the specified Uniform Resource Locator (URL).
· Deploysolution
Deploys files related to a solution from the configuration database to individual front-end Web servers in the farm.
· Displaysolution
Displays specific solution or Web Part information in a solution store.
· Editssp
Allows the site collection administrator for the Shared Services Administration site to perform the following functions:
· Change the databases that a Shared Services Provider (SSP) uses.
· Change the SQL credentials associated with the SSP databases.
· Modify the service account credentials.
· Rename an SSP
· Email
Sets the e-mail configuration settings for your server.
· Export
Exports site and subsite data from your Microsoft Office SharePoint Server 2007 installation.
· Import
Imports site and subsite data from your Microsoft Office SharePoint Server 2007 installation.
· Installfeature
Installs a feature.
· Renameserver
Changes the name of the specified server in the configuration database.
· Renamesite
Changes a URL of a host-named site collection to a new URL.
· Renameweb
Changes the URL of a subsite.
· Restore
Explains how a restoration of a site collection, an individual database, a Web application, or an entire farm is performed.
· Restoressp
Creates a Shared Service Provider using a restored database.
· Retractsolution
Retracts the specified solution’s deployment, and removes files from the front-end Web server.
· Scanforfeatures
Scans for new features in the file system, and if new features are present, installs them.
· Setconfigdb
Creates a new configuration database in a farm or joins the local computer to an existing farm’s configuration database.
· Setdefaultssp
Sets a Shared Services Provider (SSP) as the default SSP in a farm.
· Setlogginglevel
Sets the Windows event log and trace log logging level for one or more diagnostic logging categories registered in the farm.
· Setsitelock
Sets a value that specifies whether the site collection is locked and unavailable for read or write access.
· Siteowner
Sets the primary or secondary administrator of a site collection.
· Setworkflowconfig
Enables or disables the workflow settings
· Upgradesolution
Upgrades an existing solution. The solution to be upgraded could be either deployed or not deployed; however, the immediate or time parameters apply only if the solution has been deployed.
· Userrole
Adds or deletes permission levels to site groups.

22 Ways to Become Spectacularly Inspirational

1. Do important work vs. merely offering opinions.
2. Lift people up vs. tear others down.

3. Use the words of leadership vs. the language of victimhood.

4. Don’t worry about getting the credit for getting things done.

5. Become part of the solution rather than part of the problem.

6. Take your health to a level called superfit.

7. Commit to mastery of your craft instead of accepting mediocrity in your work.

8. Associate with people whose lives you want to be living.

9. Study for an hour a day. Double your learning and you’ll triple your success.

10. Run your own race. “No one can possibly achieve real and lasting success by being a conformist,” wrote billionaire J. Paul Getty

11. Do something small yet scary every single day.

12. Lead Without a Title.

13. Focus on people’s strengths vs. obsessing around their weaknesses.

14. Remember that potential unused turns into pain. So dedicate yourself to expressing your best.

15. Smile more.

16. Listen more.

17. Read the autobiography of Nelson Mandela.

18. Reflect on the words of Eleanor Roosevelt who said: “Great minds discuss ideas; Average minds discuss events; Small minds discuss people.”

19. Persist longer than the critics suggest you should.

20. Say “please” and “thank you”.

21. Love your loved ones.

22. Do work that matters.

Resource : RobinSharma

Custom Paging API

Normally in Win Application you have Paging option is available only for moving to Next or Previous record, and move to First or Last Record. Suppose if you want to set page wise navigation then you have to go for custom paging.

In codeplex you can find CustomPaging API this is an alpha release, they provide an set of inbuild methods for Record Navigation, and page navigation. You can make use this CustomPaging API to any Application both Windows or Web Application. You can download this CustomPaging API form here [Click Here To Download]

Class Description

Available Function in dsPaging


1) NumberOfRecordPerPage

Note:- This NumberOfRecordPerPage must be specify before you call any static method from below for paging at first time. This property hold how many number of records can disply per page.

Static Methods

1) List nextRow(int curentgridindex, int currentpage, int totalrowcount)

2) List previuosRow(int curentgridindex, int currentpage, int totalrowcount)

3) List nextPage(int curentgridindex, int currentpage, int totalrowcount)

4) List previousPage(int currentpage, int totalrowcount)

5) List LastRecord(int totalrowcount)

6) List FirstRecord()

7 ) List RefreshRow(int curentgridindex, int currentpage, int totalrowcount)

8 ) List GetPagePosition(int rowindex, int totalNumberofRow)


Here curentgridindex:- Refer Current Select index of the grid

currentpage:- Current Page that is displayed on the grid

totalrowcount:- Total number of record that holds (Full row count and not per page row count)

rowindex:- Same as Currentgridindex.

Sample Code:

//Move to Next Row
private void NextRow_Click(object sender, EventArgs e)
int totalrowcount = ds.Tables[0].Rows.Count;
dsPaging.NumberOfRecordPerPage = Convert.ToInt32(textBox1.Text);
List poition = dsPaging.nextRow(currentindex, currentpage, totalrowcount);
currentindex = poition[0];
currentpage = poition[1];
Noofrow = poition[2];
Any bug or Paging API question are always welcome.

Create identity to create table with data

Normally we can’t create the identity in the existing column, it must be created while creating the table. Suppose if you have a data in the table you want to add the identity in the table, we can do it in indirect way as below.

Consider the table as table1 and it contain a column as column1

Now am rename the table1 as table1_new as below

sp_rename ‘table1′,’table1_new’

Now create a new table as table1

create table table1(column1 int primary key identity(1,1))

then turn off identity

set identity_insert table1 on

Now copy all data from old table to new table as below

insert into table1(column1 )
select column1 from table1

Now turnon the identity

set identity_insert table1 off

Find the max value of column

select MAX(column1) from table1

Reseed the identity as below


Now you can make use of the table along with identity as before

Multiplication trick

To make the multiplication with some trick

Take first digit from each side

Then make cross multiple with other digit and sum the result


finally take multiple of last digit in both the side


now con cat all the result will give you the result


Similarly for little bit complex digit





Here while you join the result some time you can find more than one digit as in this case, if so you have to add the highest position of each result with other.

In our case, you have to combine 45 with 95, here 95 is two digit number and not single digit so add 9 it with 45 which result as below 54 now combine remaining one digit 4 with this 54.


similarly for last one
544+48=> 54(4+4)8=>5488

so the result is 56*98=5488

validate Datagridview column

If you want to validate the column in the datagridview then you can choose “CellValidating”

Sample Codeing is as below

private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
DataGridViewTextBoxCell cell = dataGridView1[e.ColumnIndex, e.RowIndex] as DataGridViewTextBoxCell;

if (cell != null)
char[] chars = e.FormattedValue.ToString().ToCharArray();
foreach (char c in chars)
if (char.IsDigit(c) == false)
MessageBox.Show(“You have to enter digits only”);

e.Cancel = true;

Suppose if you want to validate after pressing enter, then you can use as below
protected override bool ProcessDialogKey(KeyskeyData)
if (keyData == Keys.Enter)
DataGridViewCell currentCell = CurrentCell;
CurrentCell = null;
CurrentCell = currentCell;
return true;
return base.ProcessDialogKey(keyData);
else you can also use EditControlShowing event

void dataGridView1_EditingControlShowing(object sender,

DataGridViewEditingControlShowingEventArgs e)


if (this.dataGridView1.CurrentCell.ColumnIndex == 0)


if (e.Control is TextBox)


TextBox tb = e.Control as TextBox;

tb.KeyPress -= new KeyPressEventHandler(tb_KeyPress);

tb.KeyPress += new KeyPressEventHandler(tb_KeyPress);




void tb_KeyPress(object sender, KeyPressEventArgs e)


if (!(char.IsDigit(e.KeyChar)))


Keys key = (Keys)e.KeyChar;

if (!(key == Keys.Back || key == Keys.Delete))


e.Handled = true;





Format Data in the Windows Forms DataGridView Control

Useful coding for formation the cells in datagridview in MSDN site

To enable wordwrap in text-based cells

this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;

To specify the text alignment of DataGridView cells

= DataGridViewContentAlignment.MiddleRight;

To customize the display of null database values

this.dataGridView1.DefaultCellStyle.NullValue = "no entry";

To format currency and date values

this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format = "c";
this.dataGridView1.Columns["ShipDate"].DefaultCellStyle.Format = "d";

And also as below

dataGridView1.Columns[0].DefaultCellStyle.Format = “dd’/’MM’/’yyyy”;

//Get 13/12/2007

dataGridView1.Columns[1].DefaultCellStyle.Format = “dd’/’MM’/’yyyy hh:mm:ss tt”;

//Get 13/12/2007 5:00:11 PM

%d bloggers like this: