Monday, 11 April 2011

Calculating the document library or List size

we were having the document library in the site and wants to fixed the size of the document library. So every time the user uploads any document size has to checked if the size goes above the certain limit it should show the error to the user .

We have written the following code to achieve this :



DataTable dt;
                dt = site.StorageManagementInformation(SPSite.StorageManagementInformationType.DocumentLibrary,SPSite.StorageManagementSortOrder.Decreasing,SPSite.StorageManagementSortedOn.Size, 100);
                foreach (DataRow row in dt.Rows)
                {
                    foreach (DataColumn column in dt.Columns)
                    {
                        if (row["Title"] == "DocumentLibraryName")
                        {
                            //Compare the size in bytes
                            if (Convert.ToUInt32(row["Size"]) == 1000)
                            {
                                //Code to perform the operation
                            }
                        }
                    }


In the StorageManagementInformation we can pass the StorageManagementInformationType.DocumentLibrary, List or Document

AccessDenied Exception and redirecting to sharepoint access denied page

some times we write the code for the user who are not authorized to access the information then sharepoint default security apply then shareoint through the access denied error.
You can catch and redirect the error to default access denied page.


Use the follwoing code to do same:

try
{
//Code to be executed
}
catch(Exception ex)
{
SPUtility.HandleAccessDenied(ex);
}

Sunday, 3 April 2011

assigning permission in SQL server to create database diagram


I was required to create database diagram to view the database object but the user i have logged in was not able to view the feature. After goggling i have analyzed that user is not having enough permission.


Run the following code in sql analyzer to assign the permission to a user to create a database design


EXEC sp_dbcmptlevel 'data_base_name', '90';
go
ALTER AUTHORIZATION ON DATABASE::'data_base_name TO "domain\userid"
go
use ['data_base_name]
go
EXECUTE AS USER = N'dbo' REVERT
go

Saturday, 2 April 2011

Creating the fulltext catalog in sql server

To search on database using fulltext query database has to be indexed. 


Execute the following procedures in SQL to create the fulltext indexes on a database.


Exec sp_fulltext_database 'enable'
Exec sp_fulltext_catalog 'Resume_catalog', 'create'
Exec sp_fulltext_table 'ResumeDB', 'create', 'Resume_catalog', 'PK_ResumeDB'
Exec sp_fulltext_column 'ResumeDB', 'FileContent', 'add', null,'FileType'
Exec sp_fulltext_table 'ResumeDB','activate'
Exec sp_fulltext_table 'ResumeDB', 'start_change_tracking'
Exec sp_fulltext_table 'ResumeDB', 'start_background_updateindex'
Exec sp_fulltext_catalog 'Resume_catalog','start_full'