Zieglers

Just little about C#, .NET, SQL Server, SharePoint and SAP

Archive for April, 2010

Bulk Move for SharePoint

Posted by zieglers on April 20, 2010

Here is another generic bulk action for SharePoint: Move Documents

 Idea is similar to previous bulk actions i developed. Move operation will give more flexibility to users while working with documents in SharePoint libraries. It’ll help to organize your documents easily by allowing you to move them from one library to another in bulk.

 Sounds simple, but there are many questions to ask on move operation. Here are 2 very important questions to answer:

  • What if documents you are moving belong to one or more content types which don’t exist yet in destination library?

Answer: Before moving files, source and destination library content types are compared. Then, missing content types are added to destination library. In a way, destination library is prepared for move operation.

  • What happens to metadata of the source documents after moving it?

Answer: All metadata of source documents is also moved along with documents.

DEMO: Here is a sample move operation performed on two sample files which belong to content types CT1 and CT2, being moved from ‘Documents’ library to ‘TestLib’.

1. Sample documents in source library

2. Select documents and go to Bulk Actions -> Move.

3. Select destination library, TestLib.

4. Selected documents have been moved to destination library. Source library is empty.

5. Moved documents are TestLib library.

6. Metadata is moved with documents as well.

Let me know if you have any questions, suggestions, or interested in this functionality.

Zieglers

Advertisements

Posted in IT Stuff, SharePoint | Tagged: , , , , , | 18 Comments »

Dynamically creating form controls in SharePoint

Posted by zieglers on April 8, 2010

While doing SharePoint development, occasionally we find ourselves in situations that we need to create controls dynamically based on some user selection, querystring parameter, … etc.

Here I provide you a code snippet which you can use in custom SharePoint application pages or web parts. This code is basically,

  • creating an HTML table
  • looping thru some fields (those can be SPListItem fields or any collection you want based on which you’ll generate controls dynamically)
  • creating a SPContext based on item
  • creating FieldLabel and FormField objects using SPContext (This allows controls to be created based on their rendering and item context. For example, say Title field is string, textbox control will be created or Start Date is DateTime, then textbox with calendar control will be created.)  This means you don’t need to worry about which type of control you need to create.
  • adding FieldLabel and FormField to table rows.
  • finally adding constructed table to some other control before rendering, say to a panel.

You can download code snippet, CreateControls method, here: Creating Dynamic SharePoint Form Controls

zieglers

Posted in C#, IT Stuff, SharePoint | Tagged: , , , , , , , , | 1 Comment »