Thursday, May 27, 2010

Copy Images or Files from One Site to Another

//Get the context of the Image site
SPSite DestSite = new SPSite("Site URL");
//Access the folder under Images
SPFileCollection DestImages = DestSite.RootWeb.Folders["Images"].Files;
// Get the current site context
SPSite SourceSite = SPContext.Current.Site;
// Access the Provisioned site Webparts folder under _catalogs
SPFileCollection SourceImages = SourceSite.RootWeb.Folders["Images"].Files;
foreach (SPFile DestImage in DestImages)
{
// Load the properties of the existing file
byte[] binaryData = DestImage.OpenBinary();
// Copy the file
SPFile copiedFile = SourceImages.Add(DestImage.Name, binaryData, true);
copiedFile.Update();
}

Friday, May 21, 2010

SharePoint Search Result Open on Browser

Solution:

Add Following Javascript File to OSSSearchResults.aspx result page.

Javascript Code:

function getURLParam(strParamName)
{
var strReturn = "";
var strHref = window.location.href;

if ( strHref.indexOf("?") > -1 )
{
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam <>
{
if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 )
{

var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return unescape(strReturn);
}

Wednesday, May 19, 2010

SharePoint Immediate Alerts Not Working

There are various issues with the sharepoint alerts.

Problem 1: Not a single site sends the alerts.Problem
2: A specific site fails to send the alertsProblem
3: A specific user fails to receive the alertsProblem

Problem 1: Not a single site sends the alerts.

After registering for alerts on a SharePoint list/document library, you get the welcome email "You have successfully created an alert for 'doc lib' ". But you will never get the actual alert mail for the changes on the document/item you marked for an alert.

Reason:
There is a config/environement change that was not reflected into the config database or config cache.

Fix:

1. Stop the WSS Sharepoint timer servicestart -> admin tools -> services -> Windows Sharepoint Services timer -> stop.

2. Delete the UN used Alternate Access Mappings (CA-> Operations -> Alternate Access mappings); UN used IP configurations, orphans in the DB.

3. Clear the config cache.- Go to the local sharepoint config files folder:C:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config\ConfigDB ID- Delete all the XML files and do not delete the "cache.ini" file.- Delete all the numbers in the "cache.ini”, type 1 and save it.

4. Start the WSS Sharepoint timer servicestart -> admin tools -> services -> Windows Sharepoint Services timer -> Start.

5. Check whether the timer job is successful or not. Also see the immediate alerts status.CA -> Operations -> Timer Job Status

6. Check whether the 'alerts' is configured in Minutes: A -> Operations -> Timer Job definitions.

7. Sometimes there will be a problem with the mail provider settings. Check the SMTP Relay settings to see the IP Address configured properly.


Problem 2: A specific site fails to send the alertsReason:

There is a config/environment change in a specific site. In other scenarios, if a site is migrated from different environment or another version. So, you do not get alerts on that specific site.

Fix:

1. (Do this step if your environement is flexible)Create a new web application/new content database and test for the alerts. On success, move this perticular problematic site to the new web application/content database.

2. Force the "alerts enabled" command on the perticular site.C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN> stsadm.exe -o setproperty -pn alerts-enabled -pv "true" -url http://sitename/.You will be fine.

Other commands:

1. Though you can do all these below commands through CA UI, STSADM is preferred.
To verify whether a site has the alerts enabled:Stsadm.exe-o getproperty -url http://sitename/ -pn alerts-enabledThis will return Yes or No.

2. To disable alerts on a site:stsadm.exe -o setproperty -pn alerts-enabled -pv "false" -url http://sitename/

3. Verify the job-immediate-alerts. Should be every 5 minutes.stsadm.exe -o getproperty -url http://sitename/ -pn job-immediate-alerts

4. If the above command returns anything other than "Every 5 minutes between 0 and 59", set the timestsadm.exe -o setproperty -pn job-immediate-alerts -pv "every 5 minutes between 0 and 59" -url http://sitename/


Problem 3: A specific user fails to receive the alertsReason:

There must a problem with the registered email id. Or user might not have at least "read" access on the document library.

Fix:

1.Check for the user access on the doc library. If not, add the user with at least "read" access.It may happen that the user gets the initial mail. Coz, initial mail doesnt look for the permissions before sending the mail.

2. While configuring, use the "email id" instead of the usual "Domain\Name". If succeeded, then there must be a problem with the email id registered.

3. To confirm the email not in sync,SQL -> Associated Content Database -> Tables -> ImmedSubscriptions -> email field

Tuesday, May 11, 2010

Evaluation Version Expired but not really

A friend was building a server and ran into an issue where he was installing a fresh server, put in his trial key and assumed he did everything right, but was getting an error message: "The evaluation version of Microsoft Office SharePoint Server 2007 for this server has expired."

ACTION:
Current user updated MOSS2007 and registered his Volume License Key to the MOSS2007 Installation. Current user tries to Access his "My Site" RESULT: Current user receives following error: "The evaluation version of Microsoft Office SharePoint Server 2007 for this server has expired."

CAUSE:
Insufficient permissions for the groups WSS_WPG, WSS_ADMIN_WPG to the Registry The application pool identity for your WSS/MOSS sites *MUST* be in the "Distributed COM Users" group in order to successfully activate.

RESOLUTION:
We gave group WSS_WPG Read permissions to following registry key HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Office Server\12.0 We gave group WSS_ADMIN_WPG Full permissions to the same registry key HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Office Server\12.0 We added application pool Account ("dcomcnfg.exe") to the Distributed users We rebooted the server

By the way, these are the kind of blog posts that I like to run into when searching for answers on the Internet. They kind of feel like a KB article. Let's say you're an IT guy, but don't know what to blog about. You run into an issue, you solve it. Ideal and perfect for a post. Short and sweet. Great reference for you and the rest of the world. If they don't need the info, the don't need to read it.

The evaluation version of Microsoft Office SharePoint Server 2007 for this server has expired

Definitely not the message you want to see after paying a whole lot of bucks. This happened to a colleague of mine when he tried to setup "My Sites". In fact, same error message was thrown whenever he tried to use any feature of "MOSS Enterprise".

Here is the solution:

1. Open the associated web.config
2. Make any change and undo it
3. Save the web.config

Believe it or not that is your solution. Hope this helps to somebody

Tuesday, May 4, 2010

How to create MySite Programmatically

SharePoint provides APIs to create MySite programmtically. UserProfile object provides a method to create personal site. Following console application creates MySite for a given account:

using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;


namespace UserProfileCreate
{
class Program
{
static void Main(string[] args)
{

using (SPSite site = new SPSite("http://servername"))
{
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);

string accountName = "domainname\\username";
UserProfile userProfile;
if (profileManager.UserExists(accountName))
{
userProfile = profileManager.GetUserProfile(accountName);

userProfile.CreatePersonalSite();

}
}
}
}
}