Sunday, July 29, 2007

My Links webpart display on a page

If you want to display 'My Links' webpart on any sharepoint page, there are two ways to do.

1. My Links webpart with all the tool bar links:
  • Go to the webpart library ( Site Actions -> site settings -> galleries -> Web Parts )
  • New
  • Check for the 'Quick Links Micro view' webpart and 'Populate gallery)
  • Now, My Links web part is ready in the webpart browser.

2. My Links web part without any tool bars.

  • Go to the actual 'My Links' webpart available on the 'Profile' page.
  • context menu -> Export
  • Save the ".dwp" file on your local disk.
  • Go to the page, you wanna display the webpart -> Site Actions -> Edit Page -> Add webpart -> Import
  • Select the '.dwp' file that you just saved on the disk.

How to change the Title URL of the 'My Links' webpart

'My Links' webpart title is formed dynamically. Even though you change the URL from the properties/dwp file's detail link, page refresh will get the default My Links URL again.
Structure of the My Links title URL:
"Personal site provider URL"/_layouts/MyQuickLinks.aspx

So, if you wanna change the URL of the title, you need to change the "Personal site Provider URL", whcih can be set on the SSP settings page(Sharepoint Central Admin -> SSP -> My Site Settings -> Personal site provider)

Friday, July 27, 2007

DVD player is skipping and making noise

Issue:

last week I got a DVD from Netflix which was completely cracked and pasted with a plaseter to fool the customers. Without the knowledge, I inserted into my DELL INSPIRON machine. After that moment, whatever DVD I try to play on my lappy, it keeps skipping the voice/picture and made me irk!!

Solution:

1. Right click on My Computer
2. Select Properties
3. Click on Hardware
4. Click on Device Manager
5. Double click on IDE ATA/ATAPI controllers
6. Double click on Primary channel
7. Click Advanced Settings and check it says DMA if available and is set to Ultra DMA, mode 5.
8. Do the same for the secondary channel -- it should be Ultra DMA, mode 2.

If your PC doesn't have DMA enabled, the easiest way to re-enable it is to remove the channel and reboot. Windows will then automatically reinstall it and reset the counters that deactivated DMA in the first place.

To remove the channel:
Right click on the relevant channel in Device Manager (you know how to get there - follow steps 1 thru 5 above )
Click on uninstall
Reboot
When you have rebooted (and the drive and been recognised by Windows again), go back to Device Manager and change the setting to DMA if available.
Windows NT/2000 users reboot again. XP users, you're good to go.

Tuesday, July 24, 2007

BreakRoleInheritance throws Access is denied error.

Error Details:
While performing list item updates programmatically, you try to elevate the permissions or trying to impersonate or Brake the role inheritance, you get the following error. You will not get this error if you are logged in as an admin. Only contributor users face this error.
Error in the log:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) at Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException ex) at Microsoft.SharePoint.Library.SPRequest.UpdateRoleAssignment(String bstrUrl, Guid& pguidScopeId, Int32 lPrincipalID, Object& pvarArrIdRolesToAdd, Object& pvarArrIdRolesToRemove) at Microsoft.SharePoint.SPRoleAssignmentCollection.UpdateAssignment(Int32 principalId, SPRoleDefinitionBindingCollection bindings, Boolean addOnly) at Microsoft.SharePoint.SPRoleAssignmentCollection.Add(SPRoleAssignment roleAssignment) at MYDLL.MYDLLHandler.ItemAdded(SPItemEventProperties properties)

FIX:

Use "Allow unsafe updates=true" After each and every code line. You MUST use this statement before and after the "BreakRoleInheritance" line. Ofcrs Make it false only once, while leaving the whole code.
That should fix the issue, if you are still facing the problem, follow the below one by one. Any one of the solutions should fix your problem.

  1. Believe me, I spent countless hours to get this simple solution.
    Code the SPSite and SPWeb instances after the RunWithElevatedPrivileges(delegate() line. But initiate the context before the code line.
    Always go with Ids instead of site or webs, if you are facing the problems even after this solution.

    Guid MywebGuid = SPContext.Current.Web.ID;
    Guid MysiteGuid = SPContext.Current.Site.ID;
    //RunWithElevatedPrivileges(delegate() code block
    SPSite MySite = new SPSite(MysiteGuid)
    Keep in your mind that all the site context declarations/assignments (Guid MysiteGuid = SPContext.Current.Site.ID) should be made before the RunWithElevatedPrivileges(delegate() line. Coz, even though the user is elevated with the full control permissins using the RunWithElevatedPrivileges(delegate() line, if you declare/assign the values after the code line, while assigning the context values, control switches back to the contributor access.
    But, where as if you declare/assign the values before the code line, context will be initiated as the contributor first and then enters in the code block as the full control user with the context carried over. So no issues.
  2. Use IDs instead of ListItems.This makes sure, not to reuse an object that was created in the context of a non-administrative user
    Guid listID = properties.ListId;
    Guid listItemID = properties.ListItemId;
    SPListItem listItem = web.Lists[listID].GetItemById(listItemID);
  3. If this list is a document library, make sure you have the file checked-in before the "RunWithElevatedPrivileges" line or else check out the list item to the system account.
    properties.ListItem.File.CheckIn()
    In the case of Admin login, you were the admin and was going through the system checkout by default:
    Also check on the application pool id being the same as the elevated.
  4. Disable all the events being fired.

Sunday, July 22, 2007

IE Developer Toolbar not working

Situation:

After installing the IE dev tool bar while clicking on the 'select element by click' button, nothing happens.

Fix:


  1. Tools -> Internet options -> Security Tab -> Local Intranet -> Custom Level -> Run ActiveX Control or PlugIn (Administrator Mode).
  2. Tools -> Internet Options -> Programs -> Manage add-ons -> IE Developer Toolbar BHO -> Enable (requires browser restart).
  3. Tools -> Internet Options -> Advanced -> Enable third party browser-extensions (requires browser restart)

If you still can not fix the problem, try it on any other usual page, eg. google.com. If works, then there is an issue with the specific page that you are trying to.

Some identified code blocks:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd%22&gt;

  2. overflow:hidden

Friday, July 6, 2007

Enable drop dowm menu on a team site's top link bar

By default, Sharepoint publising site's top link bar has the two level drop down menu that allows you to hide the sub menu items until the parent menu item gets mouse over.

But, the team site's top link bar doesn't have the functionality by default.

Here are the steps to achieve the dropdown menu functionality within a team site.

  1. Locate the masterpage file for the page on which you wanna see the two level menu.
    Usually it will be "default.master" unless some one has changed the masterpage.
  2. open the default.master in the sharepoint Designer.
    Open the site in the Sharepoint Designer and access th masterpage located at "/_catalog/masterpage/default.master" from the folder list.
  3. If you do not have the sharepoint designer, then open the file directly from the following location: "C:\Program Files\Common Files \Microsoft Shared\Webserver Extensions\12\Template\Global\default.master.
  4. Locate the "SiteMapDataSource" node in the default.master code
    <asp:SiteMapDataSource .. >


    and replace it with:
    <asp:SiteMapDataSourceShowStartingNode="True"SiteMapProvider="SPSiteMapProvider"id="topSiteMap"runat="server" />

  5. To get the dynamic menu loaed each time you access the top link,
    locate the
    < SharePoint.AspMenu  > 


    and change the "StaticDisplayLevels" and "MaximumDynamicDisplayLevels" values to:

    StaticDisplayLevels="2"
    MaximumDynamicDisplayLevels="1"

  6. If you wanna explore the sub menu to further levels, increase the MasimumDynamicDisplayLevels value to the value you desire. I guess, it is limited to 4.

Monday, July 2, 2007

Extending Stsadm.exe with Custom Commands using the ISPStsadmCommand Interface

The configuration files that indicate to stsadm.exe which operations are available for execution are located in the 12 hive( C:\program files\common files\microsoft shared\web server extensions\12\CONFIG)
There 10 or more "stsadmcommands.customcommands.xml" xml configuration files located in the folder, where customcommands is arbitrary but must be unique. Through this naming convention for configuration files, stsadm.exe implements a pluggable architecture for declaring custom operations

The configuration file itself is a simple XML document with a <Commands/> root element containing one or more <Command/> sub-elements. These <Command/> sub-elements are where we declare custom operations and include two attributes name and class. As would be expected, the name attribute indicates the name of the operation to be executed by stsadm.exe. Note that the exact value of the name attribute will be specified by an administrator at runtime using the -o named parameter in order to execute the declared custom operation. The second attribute class specifies the class and .NET Assembly name where our classes that implement the ISPStsadmCommand interface live.


The .NET assembly containing our compiled custom operation(s) will be placed in the Global Assembly Cache (GAC) prior to runtime. This assembly contains one class for each custom stsadm.exe operation, and each of these classes must implement the ISPStsadmCommand interface. Each class that implements the ISPStsadmCommand interface is required to contain a GetHelpMessage method and a Run method. The GetHelpMessage method returns a string value containing help and usage information for the custom operation.

At runtime, the Run method will receive a StringDictionary parameter from stsadm.exe which consists of key/value pairs containing all named parameters, values and flags input from the WSS administrator. The Run method also takes an out type parameter which will be echoed back to the console window upon execution of the custom operation.

After writing a console application and placing the config info in the xml files, you can invoke the new command prompt.

How to create the Publishing pages programmatically into sharepoint

MOSS 2007 shipped with a customizable STSADM command that you can add any custom commands by using IStsadmcommand interface.
Create a console application with the following logic, Add this command to the STSADM.

Link to add the custom STSADM command: http://sharepointsolutions.blogspot.com/2006/09/extending-stsadmexe-with-custom.html


public void FillPublishingWebWithPages (string publishingSiteCollection, int pagesToCreate)
{
SPSite siteCollection = null;
SPWeb site = null;
PublishingSite publishingSite = null;
PublishingWeb publishingWeb = null;
try {
// get the PublishingWeb
siteCollection = new SPSite(publishingSiteCollection);
site = siteCollection.RootWeb();
publishingSite = new PublishingSite(siteCollection);
publishingWeb = PublishingWeb.GetPublishingWeb(site);
// Article Page content type
SPContentTypeId articleContentTypeID = new SPContentTypeId("0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D");

// get the ArticleLeft.aspx Page Layout
PageLayout[] layouts = publishingWeb.GetAvailablePageLayouts(articleContentTypeID);
PageLayout articlePageLayout = layouts[1];
// create a temp name...
string pageName = DateTime.Now.ToString("yyyyMMdd-HHmmss");
// create the specified number of pages
for (int i = 0; i < pagesToCreate; i++) {
PublishingPage newPage = publishingWeb.GetPublishingPages().Add(string.Format("{0}_Gend_Page_{1}.aspx", pageName, i), articlePageLayout);
newPage.Update();
}
} catch (Exception ex) {

throw new Exception(ex);
}
finally
{
// properly dispose of the resources
site.Dispose();
siteCollection.RootWeb.Dispose();
siteCollection.Dispose();
}
}