Wednesday, September 29, 2010
Some excerpts from Life
Then the fragrance will engulf the whole family in love, joy and happiness. I know The magic of love dwell only if you sacrifice your needs and selfishness for happiness of others. Nothing is more satisfying then giving other happiness instead of stealing being content with other's persons sorrow.
Monday, March 29, 2010
Show today's Birthday's and Anniversaries in Sharepoint
- lets say we have a column with the name DOB which stores the date of birth in datetime format.
- Create a computable column give it a name as DOBthisYear and add this "=TEXT(DOB,"M/D/")&TEXT(Today,"YYYY")" without first and last quotes :-)
- now lets view the list again where it shows the DOB for current year.
- Open the page in Designer and edit the page. Browse through the Datasource in the site and drag and drop the list to your place.
- Now it will add the powerful DataformWebpart. in a list view. Now add a filter to the list in the column DOBthisYear which equals [Current Date].
- Save the dataformwebpart give some formatting with the image of the employee to show up in the list.
Monday, December 28, 2009
Sharepoint Connectable Webparts - Easier way than SPS-2003
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
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
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
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 = "
// 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
Monday, August 10, 2009
Exception 0x80020009 while activating sharepoint Publishing infrastructure feature
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
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
STEP1: BACKUP:
- On Source SQL Server: Backup SharePoint Content databases.
- Open SQL Server Enterprise manger
- 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
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.
- Install the same versions of Service Packs for SQL and MOSS 2007, similar to your production server.
- 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)
- Copy backup Content database files to Destination SQL Server
- Open SQL Server Enterprise manger
- Create a database in your destination SQL, give the same name that of your backed up DB
- 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>
- 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) - Go to V3 Central Administration Page>Application Management>Create or extend Web Application
- Click on Create a new web application
- Choose any unused port no you can fancy
- Enter Database Server Name and enter Database name as WSS_Content_TEST
- Wait for operation to complete
- After application is created create a site collection, ( you can give any name eventually it'' not be used)
- Fill the details and select Team site template click Ok
- Browse to test site http://
- Check if it is working
To remove WSS_Content_TEST from a web application - Go to Central Administration, Central Administration > Application Management > Click on Content Databases
- On right hand side select the newly created web application if not already present
- Click on Database name WSS_Content_TEST
- 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 - Go to Central Administration, Central Administration > Application Management > Click on Content Databases
- On right hand side select the newly created web application if not already present
- Check the No. of sites in the site collection if its showing same no. that you had in your Restored Content DB webapplication.
- Then you are done with it. check the URL of the application, to view your restored Sharepoint Site.
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
[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
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] “;
Wednesday, November 5, 2008
Search Add-ons (Providers) on MOSS search result in IE7 / Firefox
First basics of search. I know the various ways how sharepoint handles search requests. Back from SPS 2003 configuration , advanced webpart development till Moss2007 integrated search.
For our purpose, we will use the query string keyword search( As other search options are postback with some compulsory parameters to the search result webpart in results.aspx page.
http://portal/searchcenter/Pages/Results.aspx?k=dhyan&Scope=All Sites.
<?xml version="1.0" encoding="utf-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>Search corporate</ShortName>
<Description>Searching the Corporate MOSS sites</Description>
<Url type="text/html" template="http://portal/searchcenter/Pages/Results.aspx?k={searchTerms}&s=All%20Sites"/>
</OpenSearchDescription>
As it shows: k={key word you want to pass}, Scope= {The scope defined in the portal SSP or simple All sites}
Now you create a XML file with your notepad update the content given below and upload it to a document library in your moss. Its required to call the XML from your Fav. Browser so that it installs the XML configuration for your search Add-on.
Add javascript code in a file or in a content webpart of a page and publish it.
<a href="javascript:window.external.AddSearchProvider('http://portal/adp/pages/search_add.xml');">Add Corporate Search </a>
While I after uploading my XML file named as search_add.xml , I simply refreshed the page to show the link "Add Corporate Search". And it will ask for your permission to add in the search provider. Click "yes", and choose default search provider option
Now done you can do search on the keyword from your browser on your Moss installation site.
Thursday, October 30, 2008
Configure SSO for MOSS 2007
The steps i'm following what he wrote in his blog. its only for my future reference i'll come and see my blog incase he removes this valuable information.
There are seven main activities that we need to do:
1. Create the SSO service account -- This is the account that the service will run under.
2. Create the SSO groups -- These groups are used to control who has the ability to administer SSO (export the master key) and who has the ability to manage it (add/remove application definitions.)
3. Configure the SSO Service - Set SSO to start and get it to use the service account.
4. Configure SQL Server - Authorize the SSO service account to SQL server.
5. Manage SSO - Setup SSO in MOSS including the groups and the database.
6. Manage the encryption key -- Create the encryption key that will be used for protecting the username and password information on the system.
7. Manage settings for enterprise application definitions -- Define what initial applications SSO will be setup to manage passwords for.
We need to create an account for the "Microsoft Single Sign-on Service" (SSO Service) to run as. This account has to be a domain account that has local administrative privileges for the front end web servers, must be a member of the SharePoint group Farm Administrators, must have db_creator and security administrator roles in SQL Server, and must be a member of the group that is defined as SSO administrators.
Then add the user to the Domain Admins group( this is the missing link) in order to get the local administrator privileges requirement met.
# From the Start Menu click Administrative Tools-Active Directory Users and Computers
# In the left hand pane on the Users folder right click and select New-User from the menu that appears. If your organization places service accounts in a different organizational unit (OU) you can certainly add this account to that location.
# Enter the First Name (SharePoint SSO), Last Name (Service), and User logon name (SharePointSSOSvc) fields and click the Next button. You can name the account anything you want, however, these values make it clear what the account is used for.
#Enter the a password into the Password and Confirm password fields. Uncheck the User must change password at next logon checkbox. Check the User cannot change password and Password never expires checkboxes. Click the Next button. This sets the account up to be a service account.
# Click the Finish button.
# On the user that was just created, right click and select Properties.
#Click the Member Of tab.
#Click the Add button
# Enter the group name Domain Admins and click Check Names then click OK. As mentioned above, if you're using another group to provide local administrator access to the farm servers, use that group here.
# Click the OK button.
With the user account created and added to a group that will have administrative access to the farm servers. Next we need to create the groups that we'll add the users capable of managing SSO into.
Then Create the SSO Group.
rest of the steps are SKIPPED as it has to do with sharepoint configuration
The last step:
Manage Settings for Enterprise Application Definitions ( has to do in Sharepoint)
Sunday, October 5, 2008
Deploying asp.net user control in sharepoint
This is the same content that has been posted in http://bestofcyber.wordpress.com/2008/09/16/deploying-aspnet-usercontrolsascx-declared-in-custom-aspx-pages-into-moss-2007-sites/
Consider you are developing a custom application in asp.net out of the box SharePoint for the ease of UI development and deployment ,you might need to also create user controls and use into your aspx pages.
While you are deploying usercontrols(.ascx) file ,you can follow below steps to get the usercontrols rendering in the custom aspx pages I found this way more simple and working 100% fine.
1. Create a Directory called “UserControls” in the root of your SharePoint web site on the file system E.g. C:\Inetpub\wwwroot\wss\VirtualDirectories\80\UserControls
2. Open IIS manager and in the root of your SharePoint site create a VirtualDirectory called “_controls” and point it to that newly created directory.
3. Put your user control in that newly created directory on the filesystem.
4. Open the web.config file and add the following:
Also make sure the trustlevel entry is set to the below
5. In your ASPX page change the existing register directive with the following:
<%@ Register src=”~/_controls/SomeControl.ascx” TagName=”somecontrol” TagPrefix=”uc1″ %>
6. Run your ASPX page and your control should render correctly.
Tuesday, July 29, 2008
Dataformwebpart Server variables
http://dataformwebpart.com/2007/11/07/spd-2007-data-view-parameters-you-dont-know-about/
Thursday, July 10, 2008
Get Current User Email, Login, Display Name Details
The normal code which microsoft given fails:
SPWeb site = SPContext.Current.Web;Because most of the users who don't have access to All sites won't give details of their email by the code given. If you are wondering what is all about the difference between All users see below:
SPUser user = site.CurrentUser;
string DisplayName = user.Name;
string Login = user.LoginName;
string EMail = user.Email;
string User Notes = user.Notes;
SPWeb site = SPContext.Current.Web;The code gives 3 types of different user collection so i guess the user who logged in and didn't find his email by the code above belongs to one of this group.
SPUserCollection c1 = site.Users;
SPUserCollection c2 = site.AllUsers;
SPUserCollection c3 = site.SiteUsers;
The difference between these SPUserCollection is copied from MSDN.:
I used a basic way to get the current user using (context of control HTTPCONTEXT) Context.User.Identity.Name or Page.User.Identity.Name which does the same httpcontext.
After we get the current user login i can pass it to the magic of another Class in sharepoint object Model which brings the user details.
using Microsoft.SharePoint.Utilities;
SPWeb osite = SPContext.Current.Web;
SPPrincipalInfo prin = SPUtility.ResolvePrincipal(osite,Context.User.Identity.Name , SPPrincipalType.All, SPPrincipalSource.All, osite.AllUsers, false);
writer.Write(prin.Email);
using this method u can also search the user by their Email ID, or their Display name. its a cool method who does the search on multiple fields.
Tuesday, July 1, 2008
Use explicit casting instead of DataBinder.Eval
The DataBinder.Eval method uses .NET reflection to evaluate the arguments that are passed in and to return the results. Consider limiting the use of DataBinder.Eval during data binding operations in order to improve ASP.NET page performance. <tr> <td><%# DataBinder.Eval(Container.DataItem, "field1") %></td> <td><%# DataBinder.Eval(Container.DataItem, "field2") %></td> </tr> </ItemTemplate>
Consider the following ItemTemplate element within a Repeater control using DataBinder.Eval:
Using explicit casting offers better performance by avoiding the cost of .NET reflection. Cast the Container.DataItem as a DataRowView:
<ItemTemplate>
<tr>
<td><%# ((DataRowView)Container.DataItem)["field1"] %></td>
<td><%# ((DataRowView)Container.DataItem)["field2"] %></td>
</tr>
</ItemTemplate>
Thread Safe .NET Event Technique
public event EventHandler Updated = delegate { };
protected void UpdatePrice(string mySymbol, decimal newPrice, long newVolume)
{
_priceList[mySymbol] = newPrice;
_volumeList[mySymbol] = newVolume;
Updated(this, new MarketFeedEventArgs(mySymbol, newPrice, newVolume));
}
Because in case of multithreaded environment if the event updated is not subscribed or if null it. Removes the subscription from all the other event handler. So instead of making a new copy of event each time, we should initialize the events at the first case.
People normally use like this which is performance friendly but not good practice for multithreaded environ
public event EventHandler Updated;
protected void UpdatePrice(string mySymbol, decimal newPrice, long newVolume)
{
_priceList[mySymbol] = newPrice;
_volumeList[mySymbol] = newVolume;
if(Updated != null)
Updated(this, new MarketFeedEventArgs(mySymbol, newPrice, newVolume));
}