Library tutorials & articles
SharePoint, Document Library and SQL Server
- Introduction
- Setting Up
- Code Discussion
- Conclusion
Setting Up
2 .You must create a database before you start working with the code. Open your SQL Server and create a blank database and name it as “SPSDocLibHandler”.
3. Add a table to this database. Table name is “DocInfo”. Create following fields in the table:
* Please note that “id” is an identity column.
Here is the SQL script to create this table:
CREATE TABLE [dbo].[DocInfo] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[Name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Modified] [datetime] NULL ,
[ModifiedBy] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ApproverComments] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ApprovalStatus] [int] NULL
) ON [PRIMARY]
You will find this script in “db.sql” file that is located in the “DB” folder inside the application folder. “db.sql” file also contains the script to create a stored procedure that will be used in our code. I would suggest that you just create the database and then run the “db.sql” file to create the required table and stored procedure but that’s up to you. You can follow the steps listed here to do it manually.
4. Create a stored procedure called as “sp_AddDocInfo”. Here is the SQL script:
CREATE PROCEDURE dbo.sp_AddDocInfo
(
@Name varchar(50),
@Modified datetime,
@ApprovalStatus int,
@ModifiedBy varchar(50),
@ApproverComments varchar(255)
)
as
insert into DocInfo values (@Name,@Modified,@ModifiedBy,@ApproverComments,@ApprovalStatus)
5. There is a file called as “db.config” in the root of the application folder. This one line configuration file contains connection string to your SQL Server. Edit this file in your notepad and add your SQL Server connection details.
Data Source = YourSQLServerName (Replace this with your SQL Server’s name)
Initial Catalog = SPSDocLibHandler (This is the database name)
User Id = sa (Replace this with your own user id)
Password = (Add password here, if any)
6. Copy this file “db.config” to the root of your system drive. For example, if your system drive is “C:”, copy the file to the root of “C:” drive. If your system drive is “D:” then copy the file to the root of “D:” drive.
7. There is a file named as “Install SPSDocLibHandler.bat” in your application folder. Open this file in notepad and see if you need to make any changes. This file installs your DLL into GAC, especially check the path where gacutil.exe is located on your computer. Run this file to install DLL into GAC. You can install the assembly into GAC manually as well. “SharePoint.DocLib.Handler.dll” can be found in the “bin\debug” folder inside your application folder.
8. After installing the DLL into GAC, you need to bind your assembly to the document library where this assembly will be used. Before doing that, you also need to enable “Event Handlers” on the virtual server where your SharePoint resides. If you don’t know how to do this then read this article on Microsoft’s site:
For your convenience, I am listing the steps required to enable the “Event Handlers” on your virtual server.
a) Go to SharePoint Central Administration page.
b) Click “Configure virtual server settings from the virtual server list page” under “Portal Site and Virtual Server Configuration”. This will open the “Virtual Server List” page:
c) Click on your virtual server from the list shown on this page.
d) Click on “Virtual server general settings” link.
On the bottom of the page, you will find “Event Handlers” section. Select “On” in the Event Handlers section to enable use of event handlers on the virtual server.
Now that you have enabled “Event Handlers” on your virtual server, your next step is to bind Your assembly to the document library. Following are the steps required to accomplish this:
a) From a view of the document library to which you want to attach the event handler assembly, click Modify settings and columns.
b) Click “Change advanced settings” on the page that opens for customizing the document library.
c) On the Document Library Advanced Settings page, type the strong name for the assembly in the Assembly Name box. In our case assembly name box would contain:
SharePoint.DocLib.Handler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=32bb15c33a2f8eca.
You can get the values used in the strong name by right-clicking the DLL of your assembly in the Local_Drive:\WINDOWS\assembly directory and then clicking Properties on the shortcut menu.
d) Type the fully qualified, case-sensitive name of the class in the Class Name box, which in this case is SharePoint.DocLib.Handler.LibraryEventSink
e) Reset IIS by typing iisreset at a command prompt.
9. You are now ready to test the application. Insert a document in your library and then go to your SQL Server, open the table and you will see the details of the newly added document. You can create reports based on the data in this table for the senior management. This is just one example of what you can do with SharePoint Document Libraries and the “Event Handler Toolkit”.
Related articles
Related discussion
-
High-Performance .NET Application Development & Architecture
by Manjot Bawa (0 replies)
-
Need to access Sharepoint MSDE database
by thief_ (0 replies)
-
VS.NET/sql server installation problem
by daspeac (4 replies)
-
sharepoint calendar web part with events from sql table
by converter2009 (2 replies)
-
Research topic in software
by reachsangeethamathew (0 replies)
Related podcasts
-
Stack Overflow: Podcast #28
This is the twenty-eighth episode of the StackOverflow podcast, where Joel and Jeff discuss Windows Azure, SQL Server 2008 full text search, Bayesian filtering, porn detection, and project management — among other things. Jeff met the inestimable Joey DeVilla aka Accordion Guy...
Events coming up
-
Dec
12
SharePoint Saturday Kansas City
Overland Park, United States
Join SharePoint architects, developers, and other professionals that work with Microsoft Office SharePoint Server 2007 for ‘SharePoint Saturday’, on Saturday, December 12th, 2009.
Hi,
I have one questsion, if you can reply. which format sql server store sharepoint files?
second how sqlserver manage versions history?
help will be appreciated.
Thanks,
Ars
Hello,
I am new to SharePoint, I am reseraching for my company the option of useing SharePoint Shared Document library for our docmentation system. We are a small company and need to create a standard shared docuemnt repository for our IT department.
Can anyone answere the following questions?
Thanks
Is there icensing fee's for a share point shared document library?
Can you create retention rules / periods on dcouments stored in the shared document library?
Is the shared document library?
What type of files can be stored in the shared document library? word, PDF, excell, powerpoint, onenote, miscrosoft project, visio?
Hi,
This article is very useful for me as a beginner to Sharepoint. I need a favour, there is a requirement to have a form that collects some input like description, remarks, expiry date etc and add a document to the library. It requires edit feature and delete feature too. Can you please guide me how to achieve in sharepoint, THANKS IN ADVANCE.
Please mail at reachbaala@yahoo.com
Thanks, Bala
This thread is for discussions of SharePoint, Document Library and SQL Server.