Saturday, May 9, 2009

SPGridview Grouping. Is it easy to apply??

Well, have you ever tried to create new sharepoint webpart with SPGrdiview and tried to enable grouping??

For the first time you call your grid it will work fine, but if you tried to use it in searching page(like you have textbox and submit button to bind the data to your grid based on entered text), it will come up with annoyed ASP.NET yellow error page saying:

" System.ArgumentNullException: Value canot be null "

the problem happened while rendering the rows again after the postback.
To solve this problem follow the steps below:
  1. Create new class @ your webpart project calling "SPGridViewGrouping".
  2. Let this class inherits from "SPGridview", your class should look like this:

    class SPGridViewGrouping : SPGridView
    {
    protected override void LoadControlState(object savedState)
    {
    base.LoadControlState(savedState);
    if (this.DataSource == null)
    {
    this.InvokeRequiresDataSource();
    }
    }
    public event EventHandler RequiresDataSource;
    private void InvokeRequiresDataSource()
    {
    //throw new NotImplementedException();
    EventHandler handler = this.RequiresDataSource;
    if (handler != null)
    {
    handler(this, new EventArgs());
    }
    }
    }
  3. At your webpart class create your grid object from "SPGridViewGrouping" NOT "SPGridview".
    SPGridViewGrouping oGrid = new SPGridViewGrouping();
  4. Add handler calling your menthod created @ SPGridViewGrouping
    oGrid.RequiresDataSource += new EventHandler(oGrid_RequiresDataSource);
  5. At this handler will look like:
    void oGrid_RequiresDataSource(object sender, EventArgs e)
    {
    //throw new NotImplementedException();
    oGrid.DataBind();
    }
  6. Enjoy your grouping.

Wednesday, March 11, 2009

Truncate MS SQL transaction Log file for SharePoint 2007 DB

One of the most painful issues to the SharePoint administrator is truncating the transaction log file for sharepoint DB.
If you tried to do shrinking thru:

1-RightClick on DB --> tasks -->Shrink -->Files

Result: NO CHANGES

2- Using T-SQL command:
DBCC SHRINKFILE('WSS_Content_WebApp_log',50);

Result: Error Message: Cannot shrink log file 2 (WSS_Content_WebApp_log) because all logical log files are in use.

Now the steps to avoid popular problems u faced doing this task.

– Truncate the log by changing the database recovery model to SIMPLE
ALTER DATABASE WSS_Content_WebApp
SET RECOVERY SIMPLE;
GO
– Shrink the truncated log file to 5 MB
DBCC SHRINKFILE (WSS_Content_WebApp _Log, 5);
GO
– Reset the database recovery model.
ALTER DATABASE WSS_Content_WebApp
SET RECOVERY FULL;
GO

NOTE: Don't leave ur db Recovery in SIMPLE mode...this will cause some problems when u try to delete site collection from sharepoint central admin.
ALWAYS keep it in FULL mode.

Wednesday, January 21, 2009

SmartTool for SharePoint 2007

Long time.....
well let's go to the point. at CodePlex site sps geeks have been published a collection of awsome tools for Moss 2007 development.
It is SmartTools.
Actually i dowonloaded "What's New" webpart for "jantielens" with the source code.

- While testing it, i found a problem :
"List of content types" didn't work correctly.

To fix this problem.....@ the source code itself:

1- Inside this method " private string GetQueryContentTypePart(string contentTypes, ContentTypesOptions option) "
2- Replace the "Switch" statment with code mentioned here.


I hope this will help.