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] “;

Wednesday, November 5, 2008

Search Add-ons (Providers) on MOSS search result in IE7 / Firefox

Today while reading an article found a very good trick for configuring the search provider/ add-ons for your favorite browser. Which allows you to quick websearch. Now how about doing quick search on your MOSS installation. I'll show you step by step for doing this.

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}&amp;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

With the vague detail provided my MSDN, a normal person like me couldn't make it out how to setup the SSO repository for MOSS 2007. With a brave ambition i started to figure it out by reading only technet steps. Its as always filled with confusion, as where to configure a domain account. Is it for the local machine or the entire domain tree of the company. With the help of Robert L. Bogue, he showed the missing link for SSO mystery.

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

Shown a good way to put custom usercontrols to work with sharepoint pages.

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.