Sharepoint Insight by Namwar Rizvi

Sharepoint Tips, Tricks and inside knowledge from real world experience by Namwar Rizvi

Archive for the ‘Tips’ Category

How to generate a valid SharePoint FileName

Posted by namwar on June 17, 2010


SharePoint imposes several restrictions for the filenames. To get the details of all these restrictions, please check this support article from Microsoft. I have created a utility function to convert a given string to a valid SharePoint filename. This function is valid for SharePoint 2003, 2007 and 2010. Here you go

public string ConvertToValidSharePointFileName(string originalFileName)
        {
            char[] InvalidFilenameCharacters = new[] {'\\', '/', ':', '*', '?', '"', '<', '>', '|', '#', '{', '}', '%', '~','&' };
            string[] InvalidFileNameStrings = new[] { ".files", "_files", 
                "-Dateien", "_fichiers", "_bestanden","_file", 
                "_archivos", "-filer", "_tiedostot", "_pliki", 
                "_soubory","_elemei", "_ficheiros", "_arquivos", 
                "_dosyalar", "_datoteke","_fitxers", "_failid", 
                "_fails", "_bylos", "_fajlovi", "_fitxategiak"};
            
            string validSharePointFileName = originalFileName;

            //Remove Invalid characters
            validSharePointFileName = validSharePointFileName.Remove(InvalidFilenameCharacters);
            
            //Remove consecutive periods(..)
            while (validSharePointFileName.Contains(".."))
            {
                validSharePointFileName = validSharePointFileName.Replace("..", ".");
            }

            //Remove reserved words from end
            foreach (string s in InvalidFileNameStrings)
            {
                if (validSharePointFileName.EndsWith(s))
                {
                    if (validSharePointFileName.Length > s.Length)
                    {
                        validSharePointFileName = validSharePointFileName.Substring(0, validSharePointFileName.Length - s.Length);
                    }
                }
            }

            //Remove period (.) at end
            if (validSharePointFileName.EndsWith("."))
            {
                validSharePointFileName = validSharePointFileName.Remove(validSharePointFileName.Length - 1, 1);
            }

            //Remove period (.) at end
            if (validSharePointFileName.StartsWith("."))
            {
                validSharePointFileName = validSharePointFileName.Remove(0, 1);
            }

            return validSharePointFileName;
        }

Posted in C#, Solutions, SP2010, Tips | Tagged: , , , , | Leave a Comment »

How to find Microsoft.SharePoint.ApplicationPages.dll and some other assemblies

Posted by namwar on June 12, 2010


You may be wondering where to find Microsoft.SharePoint.ApplicationPages.dll , if you are creating a new SharePoint application page? But don’t worry, it resides in _app_bin folder of your SharePoint site’s virtual directory.

Assuming your IIS inetpub is at C then the exact path of Microsoft.SharePoint.ApplicationPages.dll is

C:\Inetpub\wwwroot\wss\VirtualDirectories\<Your Virtual Server >\_app_bin\Microsoft.SharePoint.ApplicationPages.dll

Here is the full list of assemblies at _app_bin folder:

  1. Microsoft.Office.DocumentManagement.Pages.dll
  2. Microsoft.Office.officialfileSoap.dll
  3. Microsoft.Office.Policy.Pages.dll
  4. Microsoft.Office.SlideLibrarySoap.dll
  5. Microsoft.Office.Workflow.Pages.dll
  6. Microsoft.Office.WorkflowSoap.dll
  7. Microsoft.SharePoint.ApplicationPages.dll
  8. STSSOAP.DLL

Posted in Information, Object Model, Tips, Troubleshooting | Tagged: , , , , | Leave a Comment »

Access Denied for SharePoint Site Owner

Posted by namwar on February 24, 2010


There are times when SharePoint can even deny the Site Owner to access his/her site. There are numerous reasons behind this issue but I just want to give you the solution. So here it is:

Step 1:

Run following stsadm command after replacing place holders, mentioned in <>, by actual values:

stsadm -o siteowner -url <YourSiteUrl> -ownerlogin <Domain\AnyValidUser>

 Step 2:

Run following stsadm command after replacing place holders, mentioned in <>, by actual values:

stsadm -o siteowner -url <YourSiteUrl> -ownerlogin <Domain\SiteOwnerLogin>

Thats it. Now access the site by Site Owner user and you will be allowed.

Posted in Solutions, Tips, Troubleshooting | Tagged: , , | Leave a Comment »

How to debug Email Event Receiver

Posted by namwar on January 14, 2010


Normally when you debug an event receiver in SharePoint, you attach your debugger with w3wp.exe process. But email received event is not processed by this process.

Instead, you need to attach your debugger with OWSTIMER.exe process. This is the “Windows SharePoint Services Timer” service.

If this process is not listed in your processes list then click on “Show processes from all users” to display all processes similar to following:

OWSTimer image

Posted in Debugging, Tips | Tagged: , , | Leave a Comment »

Reverse Engineer the Schema of any List in SharePoint

Posted by namwar on December 26, 2009


If you have ever designed a custom list then you may already felt the pain of creating the schema of it and writing the whole CAML. Sometimes, we just need to enhance an already existing list by creating our own custom list for which we want to copy the existing schema and do the necessary changes.

You can retrieve the schema of any list by using the owssvr.dll call from your browser. Following is the syntax

http://<YourServer>/_vti_bin/owssvr.dll?Cmd=ExportList&amp;List=<YourListGuid>&#8221;

By replacing the Server and List GUID in above url will return you the XML Schema of the list.

To make thing easier, I have created a Feature to add a custom action in Settings menu called “Display Schema“, Click it and you will get the schema of the list.

Steps to create the feature:

1. Create a new folder called “DisplaySchema” in Features folder.

2. Create Feature.xml file and paste the following code

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="{A66E6CBA-8EA1-4c28-B233-52B3D7FF352B}"
    Title="Display List Schema"
    Description="This feature adds a custom menu item in Settings menu to display List Schema"
    Version="1.0.0.0"
    Scope="Site"
    xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="Elements.xml" />
  </ElementManifests>
</Feature>

3. Create Elements.xml file and paste the following code

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- List Toolbar Settings Menu Dropdown -->
  <CustomAction Id="DisplayListSchema"
    RegistrationType="List"
    GroupId="SettingsMenu"
    Location="Microsoft.SharePoint.StandardMenu"
    Sequence="1000"
    Title="Display Schema"
	Description="Displays schema of the list">
    <UrlAction Url="~site/_vti_bin/owssvr.dll?Cmd=ExportList&amp;List={ListId}"/>
  </CustomAction>
</Elements>

4. Install the feature by using stsadm command line tool.
5. Activate it.
6. Navigate to any list, Document Library, Tasks list etc. and click Settings, and then click Display Schema.
You will get the schema of that list. Copy it and enjoy!

Posted in Customization, Feature, Solutions, Tips, Tools | Tagged: , , , | 2 Comments »

List of all possible Content Place Holders of SharePoint

Posted by namwar on December 21, 2009


For a handy reference I am listing all possible Content Place Holders in SharePoint pages. This list is obtained from here

Content placeholder Description
PlaceHolderBodyAreaClass Additional body styles in the page header
PlaceHolderBodyLeftBorder Border element for the main page body
PlaceHolderBodyRightMargin Right margin of the main page body
PlaceHolderCalendarNavigator Shows a date-picker for navigating in a calendar when a calendar is visible on the page
PlaceHolderFormDigest The “form digest” security control
PlaceHolderGlobalNavigation The global navigation breadcrumb
PlaceHolderHorizontalNav Top navigation menu for the page
PlaceHolderLeftActions Bottom of the left navigation area
PlaceHolderLeftNavBar Left navigation area
PlaceHolderLeftNavBarBorder Border element on the left navigation bar
PlaceHolderLeftNavBarDataSource Data source for the left navigation menu
PlaceHolderLeftNavBarTop Top of the left navigation area
PlaceHolderMain Main content of the page
PlaceHolderMiniConsole A place to show page-level commands, for example, WIKI commands such as Edit Page, History, and Incoming Links
PlaceHolderNavSpacer The width of the left navigation area
PlaceHolderPageDescription Description of the page contents
PlaceHolderPageImage Page icon in the upper-left area of the page
PlaceHolderSearchArea Search box area
PlaceHolderSiteName Site name
PlaceHolderTitleAreaClass Additional styles in the page header
PlaceHolderTitleAreaSeparator Shows shadows for the title area
PlaceHolderTitleBreadcrumb Main content breadcrumb area
PlaceHolderPageTitleInTitleArea Page title shown immediately below the breadcrumbs
PlaceHolderTitleLeftBorder Left border of the title area
PlaceHolderTitleRightMargin Right margin of the title area
PlaceHolderTopNavBar Top navigation area
PlaceHolderUtilityContent Extra content at the bottom of the page
SPNavigation Empty by default in Windows SharePoint Services 3.0. Can be used for additional page editing controls.
WSSDesignConsole The page editing controls when the page is in Edit Page mode (in the browser, click Site Actions, and then click Edit Page)

UPDATE: An excellent visual reference to above mentioned Content Place Holders can be found here

Posted in Customization, Tips | Tagged: | Leave a Comment »

Displaying only Year in SharePoint Calculated Column

Posted by namwar on November 26, 2009


I wanted to display just the year of a DateTime column of SharePoint. I created a calculated column and set the formula to Year([MyDateTimeColumn]). The result I got was 2,009 ; 2,008 etc. which offcourse incorrect for year. After searching through internet, I found a good article solved my problem.

The correct formula is TEXT(YEAR([MyDateTimeColumn]),”000″)


Posted in Architecture, Customization, Solutions, Tips | Tagged: , , , | Leave a Comment »

SharePoint Foundation 2010 – What is it and What do you need to use it?

Posted by namwar on November 1, 2009


In the upcoming version of SharePoint i.e. SharePoint 2010, Windows SharePoint Services 3.0 has been evolved and got a new name called “SharePoint Foundation (SF)”. This will align it more to other Microsoft technologies like Windows Presentation Foundation (WPF) and Windows Communication Foundation (WCF).

SF extends the feature set offered by WSS 3.0 . It provides you a platform with right tools to build your collaborative web sites. Microsoft has published a paper to describe the business value of having SF 2010. You can read the paper here.

As expected, Microsoft has designed SF2010 for 64bit systems only. There is no 32 bit version of it. Following is the basic requirements list to install SF 2010 as described by Microsoft in the paper mentioned above:

SERVER ENVIRONMENT:

  • Windows Server® 2008 64-bit operating system with SP2 or later, OR Windows Server 2008 R2 64-bit
  • Microsoft SQL Server® 2005 64-bit with SP2, SQL Server 2005 Express 64-bit, SQL Server 2008 64-bit or SQL Server 2008 Express 64-bit
  • Microsoft .NET Framework 3.5 with SP1 installed

CLIENT ENVIRONMENT:

Level 1 Internet browser options for Windows:
  • Windows Internet Explorer® 7 32-bit
  • Windows Internet Explorer 8 32-bit
  • Firefox 3.x 32-bit
Level 2 Internet browser options:
  • Windows Internet Explorer 7 64-bit
  • Windows Internet Explorer 8 64-bit
  • Firefox 3.x on non-Windows operating system
  • Safari 3.x

 

Posted in Tips | 3 Comments »

Custom Edit Form for SharePoint Lists

Posted by namwar on October 21, 2009


If you want to set a custom edit form to your Sharepoint List then please make sure you follow these Golden Rules as correctly suggested by Hugo in a SharePoint news group.

  1. NEVER delete or rename the default pages…
    when you want to create a new EditForm.aspx it’s best to copy it to
    another file and then edit the original one (without renaming it and
    without reassigning the supporting files)…
  2. DON’T ever delete the webparts that exist.
    It’s better to hide them and create new ones “side-by-side”.

These rules are real time savers and I will highly encourage every reader to follow them.

Posted in Customization, Errors, Tips | Tagged: , , , | 1 Comment »

How to use Case statement in RenderPattern of a Custom Field Type

Posted by namwar on October 14, 2009


While designing a custom field type, you may sometime need to render different HTML based on the value of field. For example, if you want to display Red,Amber, Green traffic light images to highlight High,Medium, Low value then you need to dynamically switch image url based  on the value of the field.

In CAML, you have Case structure to implement this switching logic. It works very much like the C# switch-case statement. Following is an example of RenderPattern of a custom field which display different images based on the value of the field.

<RenderPattern Name="DisplayPattern">
      <Switch>
        <Expr>
          <Column />
        </Expr>
        <Case Value="1" >
          <HTML><![CDATA[<img alt="Red" src="/_layouts/IMAGES/ewr210m.gif" />]]></HTML>
         </Case>
        <Case Value="2" >
          <HTML><![CDATA[<img alt="Amber" src="/_layouts/IMAGES/ewr211m.gif"]]></HTML>
        </Case>
        <Case Value="3" >
          <HTML><![CDATA[<img alt="Green" src="/_layouts/IMAGES/ewr209m.gif"]]></HTML>
        </Case>
        <Default>
            <HTML><![CDATA[<span>No Value</span>]]></HTML>
        </Default>
      </Switch>
    </RenderPattern>

Posted in Tips | Tagged: , , , | Leave a Comment »