Monday, December 28, 2009

Sharepoint Connectable Webparts - Easier way than SPS-2003

Found a really helpful method to develop connectable webparts where we can pass objects as reference to another webpart.

http://businessagility.typepad.com/the_edge/2008/11/developing-custom-connectable-web-parts-in-microsoft-office-sharepoint-server-2007.html

The interface which contains the data to pass would look similar to the following:
public interface IDataProviderInterface
{
String myFilterValue { get; set; }
}


The Provider Web Part then implements the data provider interface and provides a method to communicate the data by using the ConnectionProvider method attribute.

[ConnectionProvider("DisplayName", "ID")]
public IDataProviderInterface ProviderMethod()
{
return this as IDataProviderInterface;
}


The Consumer does not directly implement the interface; rather it provides a method to consume the data as specified by the ConnectionConsumer method attribute.

[ConnectionConsumer("DisplayName", "ID")]
public void ConsumerMethod(IDataProviderInterface dataProv)
{
_providedData = dataProv;
}

Wednesday, December 9, 2009

How to find the worker process aka w3wp.exe running for ur Sharepoint Web application

This post has to be modified for IIS 6.

When you require the need of attaching your webpart debugger to the current running instance of W3WP process container for your SharePoint application from Visual Studio, you find only the ID for the W3wp currently running in the server.
To identify the current running worker process in IIS 7.0 for your application to debug under VS 2005 or VS2008.

IIS 7.0 has a wonder administration tool called appcmd.exe from which every tasks for maintaining IIS can be batched process using this command tool.
Located in %systemroot%\system32\inetsrv\

Now to display the list of web application running under W3WP process run appcmd with this parameters:
C:\Windows\System32\inetsrv>appcmd list wp
you will see

WP "4900" (applicationPool:Portal)
WP "4540" (applicationPool:TimeSheet9898)
WP "3600" (applicationPool:SharePoint Central Administration v3)


for IIS 6.0 I'll post later.

Monday, December 7, 2009

Enable Debugging in Sharepoint Site

This comes very handy .. How to enable the debugging in your newly created development Sharepoint Site.
Turn on the call stack (CallStack="true")
Disable custom errors in Visual Studio (<customerrors mode="Off"></customerrors>)
Enable compilation debugging (<compilation debug="true"></compilation>)

Wednesday, September 16, 2009

Good Practices How about this, to retrieve items from Large SPList

Use PortalSiteMapProvider (Microsoft Office SharePoint Server 2007 only).

Steve Peschka's white paper Working with Large Lists in Office SharePoint Server 2007 describes an efficient approach to retrieving list data in Office SharePoint Server 2007 by using the PortalSiteMapProvider class. PortalSiteMapProvider provides an automatic caching infrastructure for retrieving list data. The GetCachedListItemsByQuery method of PortalSiteMapProvider takes an SPQuery object as a parameter, and then checks its cache to determine whether the items already exist. If they do, the method returns the cached results. If not, it queries the list and stores the results in a cache. This approach works especially well when you are retrieving list data that does not change significantly over time. When data sets change frequently, the class incurs the performance cost of continually writing to the cache in addition to the costs of reading from the database. Consider that the PortalSiteMapProvider class uses the site collection object cache to store data. This cache has a default size of 100 MB. You can increase the size of this cache for each site collection on the object cache settings page for the site collection. But this memory is taken from the shared memory available to the application pool and can therefore affect the performance of other applications. Another significant limitation is that you cannot use the PortalSiteMapProvider class in applications based on Windows Forms. The following code example shows how to use this method.

Good Coding Practice

Using PortalSiteMap Provider
C#

// Get the current SPWeb object.
SPWeb curWeb = SPControl.GetContextWeb(HttpContext.Current);

// Create the query.
SPQuery curQry = new SPQuery();
curQry.Query = "
Hotel
";

// Create an instance of PortalSiteMapProvider.
PortalSiteMapProvider ps = PortalSiteMapProvider.WebSiteMapProvider;
PortalWebSiteMapNode pNode = ps.FindSiteMapNode(curWeb.ServerRelativeUrl) as PortalWebSiteMapNode;

// Retrieve the items.

SiteMapNodeCollection pItems = ps.GetCachedListItemsByQuery(pNode, "myListName_NotID", curQry, curWeb);

// Enumerate through all of the matches.
foreach (PortalListItemSiteMapNode pItem in pItems)
{
// Do something with each match.
}

Friday, August 28, 2009

Quick reference to add PDF or any icons

http://support.microsoft.com/kb/832809

Monday, August 10, 2009

Exception 0x80020009 while activating sharepoint Publishing infrastructure feature

I had some issues while activating publishing feature for sharepoint. Found this issue was common for many users. This issue was solved using the command line tool STSADM


stsadm -o activatefeature -filename publishing\feature.xml -url http://serverURL -force
stsadm -o activatefeature -filename publishingresources\feature.xml -url http://serverURL -force

stsadm -o activatefeature -filename publishingSite\feature.xml -url http://serverURL -force

stsadm -o activatefeature -filename publishingweb\feature.xml -url http://serverURL -force

stsadm -o activatefeature -filename publishinglayouts\feature.xml -url http://serverURL -force

stsadm -o activatefeature -filename navigation\feature.xml -url http://serverURL -force

then do an IISRESET

Monday, June 22, 2009

How to create Dropdownlist control for a SQL datasource using Sharepoint Designer

By default when you open a SQL datasource , and drag and drop the view to create a Input form for that datasource, the sharepoint point creates all fields as Text Boxes. This is not what a normal user wants.It would be greate when he can't choose a value from a dropdown and thus reduces the chances of duplicate records or wrongly spell words in the SQL tables.

Thus I have recreated the textbox control to dropdown, remember the main trick is
changing the textbox control to sharepoint inbuilt dvdropdownlist and change the binding to
'SelectedValue','SelectedIndexChanged'


<asp:SqlDataSource runat="server" id="SqlDataSource1" ConnectionString="Data Source=bwcmossdev;Initial Catalog=bwcSalesExec;User ID=sa;Password=webtech@123" ProviderName="System.Data.SqlClient" SelectCommand="SELECT rtrim(SALESMOT_SalesTeams.SalesTeamName) [SalesTeamName], SALESMOT_SalesTeams.SalesTeamManager, SALESMOT_SalesTeams.IsActive, Global_DivisionsNLocations.Description, SALESMOT_SalesTeams.SalesTeamID FROM SALESMOT_SalesTeams INNER JOIN Global_DivisionsNLocations ON SALESMOT_SalesTeams.SalesTeamDivision = Global_DivisionsNLocations.GlobalLocationId where SALESMOT_SalesTeams.isActive =1" />

<SharePoint:DVDropDownList runat="server" id="ff2{$Pos}" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'SelectedValue','SelectedIndexChanged','',ddwrt:EscapeDelims(string('')),'@SalesTeamID')}" selectedvalue="{@SalesTeamID}" datasourceid="SqlDataSource1" datatextfield="SalesTeamName" datavaluefield="SalesTeamID" />

Monday, June 15, 2009

Content DB Restore by SQL DB move, showing zero sites

First of all i'll tell you the steps how to copy your existing Site DB to a new Server.
STEP1: BACKUP:

  1. On Source SQL Server: Backup SharePoint Content databases.
  2. Open SQL Server Enterprise manger
  3. Right Click a database (For ex: WSS_Content)>All Tasks>Backup Database>Database Complete>Backup to disk>Add>Filename>Provide a path & filename>Ok>Ok
Question:How to find name of Content databases:
Central Admin>Application Management>Content databases>Select web application from Right Hand Side Top drop down list
Database name will be displayed.

Step 2:Prepare the destination SQL server and Web server.

  1. Install the same versions of Service Packs for SQL and MOSS 2007, similar to your production server.
  2. Ensure you use the similar Admin user which would have full access as service account for both Web server and SQL server. (Check Security Administrators & Database Creators)
Step 3: RESTORE CONTENT DATABASE TO DESTINATION SERVER
  1. Copy backup Content database files to Destination SQL Server
  2. Open SQL Server Enterprise manger
  3. Create a database in your destination SQL, give the same name that of your backed up DB
  4. Databases>Right Click>All Tasks>Restore database>Restore as Database>Type name of Content Database>From device>Select device>disk>Add>Browse to backup files>Ok>
Step 4: RESTORING SITES FROM DATABASES
  1. Create a new web application http:// at port 80 with content database name WSS_Content_TEST ( this Database we will remove and replace with out backed up DB)
  2. Go to V3 Central Administration Page>Application Management>Create or extend Web Application
  3. Click on Create a new web application
  4. Choose any unused port no you can fancy
  5. Enter Database Server Name and enter Database name as WSS_Content_TEST
  6. Wait for operation to complete
  7. After application is created create a site collection, ( you can give any name eventually it'' not be used)
  8. Fill the details and select Team site template click Ok
  9. Browse to test site http://
  10. Check if it is working

    To remove WSS_Content_TEST from a web application
  11. Go to Central Administration, Central Administration > Application Management > Click on Content Databases
  12. On right hand side select the newly created web application if not already present
  13. Click on Database name WSS_Content_TEST
  14. Check remove content database checkbox and click OK

    To attach restored content database to a new web application:
    Open a command prompt and browse to
    c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin>
    Run following command
    stsadm -o addcontentdb -url http:// -databaseserver Mossdev -databasename BackupDBName -assignnewdatabaseid
    Where Mossdev is my Database server name
    BackupDBName is my BackedUp Database that i've restored in SQL.

    Check if the sites collection has be restored in your new server

  15. Go to Central Administration, Central Administration > Application Management > Click on Content Databases
  16. On right hand side select the newly created web application if not already present
  17. Check the No. of sites in the site collection if its showing same no. that you had in your Restored Content DB webapplication.
  18. Then you are done with it. check the URL of the application, to view your restored Sharepoint Site.
Note: If still the new restored Content DB is showing "Current Number of Sites" is 0
Then there might be an existing Content DB id in your sharepoint installation configuration DB.
Here is the workaround. First find out the Id of the sites (site collection) in the [restored_db].Sites then delete the line in the [Config_db].SiteMap with the same Id. Now attach the content_db and you should see the sites.
Or what you can do is change the ID inside the [config_db].SiteMap to something else, maybe change a number.

Friday, May 22, 2009

Installing Sharepoint Visual Studio Extensions in XP machine Hack

We need to open up the Registry in the XP machine and create 12.0 folder then add a string value "Sharepoint"="Installed"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0]
"Sharepoint"="Installed"


Thats it .. enjoy installing the development features of Sharepoint in XP machine.
Credit for discovering this hack goes to Janne Mattila's , he also got it from somewhere else.

Enjoy the Hack

Thursday, March 26, 2009

Delete List Items or Document Library Items Forever (Without sending to recycle bin)

Some weeks back I got a post from my co-worker to delete all the items from a list without being overloading items in recycle bin.

There is a good post in http://code.msdn.microsoft.com/SharePointListDelete which I'm keeping it for my own reference. This post is not my original content, and I'm only keeping this post for my own reference in development.

Firstly this method of deleting the items is more efficient with the performance on the execution for deleting let's say 10,000 of records. Also it sends only one request to delete all the records instead of individual request per items. Also I noted one more useful method spSite.RootWeb.ProcessBatchData(sbDelete.ToString());


public static void DeleteAllItems(string site, string list)
{
using (SPSite spSite = new SPSite(site)){
using (SPWeb spWeb = spSite.OpenWeb()){
StringBuilder sbDelete =BuildBatchDeleteCommand(spWeb.Lists[list]); spSite.RootWeb.ProcessBatchData(sbDelete.ToString()); spWeb.RecycleBin.DeleteAll();
//
Note: For me it didn't work for rootweb, i used spWeb.
ProcessBatchData(sbDelete.ToString());}}}
Now the method to call the XML request. This will build a list of all the items to get deleted.
private static StringBuilder BuildBatchDeleteCommand(SPList spList)
{

StringBuilder sbDelete = new
StringBuilder();

sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");

string command = "<Method><SetList Scope=\"Request\">" + spList.ID +

"</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";
// Remember to delete the document library you have to add this <SetVar> too //<SetVar Name="owsfileref">{server-relative-url}</SetVar> The relative URl to the document to delete, where SPFile instance's ServerRelativeUrl property.
foreach (SPListItem item in spList.Items)
{
sbDelete.Append(string.Format(command, item.ID.ToString()));
}
sbDelete.Append("</Batch>");

return sbDelete;
}
Also I got variant of this method to delete purge the items similar way. This can be executed in the list object without calling the Rootweb.You have to call only the CAML query with each fields ids defined. This will also run as a single request batch command.

<Batch OnError="Continue">
<Method ID="1" Cmd="Delete">
<Field Name="ID">1</Field>
</Method>
<Method ID="2" Cmd="Delete">
<Field Name="ID">2</Field>
</Method>
……… so on
</Batch>

Similary for deleting the documents from the list , add the following line inside the Method tag.
<Field Name="FileRef">http://spdev/Library Name/Msg-4218faa2-727e.xml</Field>

The commands can also be executed from the Sharepoint Webservices UpdateListItems() method.

Wednesday, March 11, 2009

Sharepoint Image Rolling (Content) Webpart

Recently in one of the project there is a requirement of building a image rolling webpart. As there was time constraint to build a entire Visual Studio webpart, I took help of Content Editor Webpart and put down simple Javascript and HTML codes to make it working.
You need to create a picture library to store your images. Only disadvantage is that you need to hardcode the images and add some scripts code for any images you want to add for rolling in future.

1) Drag and drop a Content Editor webpart in your ASPX page.

2) Add the complete Script below:
<script language="javascript" type="text/javascript">

<!--
var image="";
var banners=0;
var bannerImage = new Array(4); // Modify the array count if new images added
bannerImage[0]= "http://mywebserver/PublishingImages/Image1.jpg";
bannerImage[1]= "http://mywebserver/PublishingImages/Image2.jpg";
bannerImage[2]= "http://mywebserver/PublishingImages/Image3.jpg";
bannerImage[3]= "http://mywebserver/PublishingImages/Image4.jpg";
// <<Insert new Image array here>>

var bannerURL = new Array(bannerImage.length);
bannerURL[0]= "http://www.google.com";
bannerURL[1]= "http://www.yahoo.com";
bannerURL[2]= "http://mywebserver/news/Pages/CCNNEAwards.aspx";
bannerURL[3]= "http://mywebserver/default.aspx";
// <<Insert New Image URL here>>

var link = bannerURL[0] ;
function cycle() {
if (++banners > bannerImage.length-1) banners=0;
document.banner1.src = bannerImage[banners];
window.setTimeout('cycle();',6000);
}

function urlswitch() {
link= bannerURL[banners];
return link;
}
//-->
</script>

<center>
<a href="#" onclick="this.href=urlswitch()">
<img width="225" border="0" src="http://mywebserver/Rotating%20Images/Image1.jpg" name="banner1"></a> </center>

3) To add new Image
To add a new image(Image5.jpg) just add a this line
//** URL of the image**
bannerImage[4]= "http://mywebserver/PublishingImages/Image5.jpg";
after
bannerImage[3]= "http://mywebserver/PublishingImages/Image4.jpg";
Also update the number of array item to 5 in the line.
var bannerImage = new Array(5);

Add a URL to the New Image
Add this line
bannerURL[4]= "http://mywebserver/department/HR/default.aspx"; // **URL to drill down to a site after the line containing “bannerURL[3] “;