in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Spiral Out

  • Content Query Web Part Display all fields + values

     I was using a custom xslt to display all the field names  in Content Query Web part. Very useful to debug while writing custom style sheets.

     

    I needed to see values along with it so this XSLT will display values along with Field names

     <code>

    ---------------------------------------------------------------------------------- 

     <xsl:template name="AllFields" match="Row[@Style='AllFields']" mode="itemstyle">
        <xsl:param name="CurPos"/>
              <xsl:variable name="SafeLinkUrl">
                <xsl:call-template name="OuterTemplate.GetSafeLink">
                    <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:variable name="SafeImageUrl">
                <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
                    <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:variable name="DisplayTitle">
                <xsl:call-template name="OuterTemplate.GetTitle">
                    <xsl:with-param name="Title" select="@Title"/>
                    <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
                </xsl:call-template>
            </xsl:variable>
            <xsl:variable name="LinkTarget">
                <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>
            </xsl:variable>
            <div id="linkitem" class="item">        
                <xsl:for-each select="@*">               
                        <span style ="font:bold">    <xsl:value-of select="name()" /> </span>  : <xsl:value-of select="."/> <br/>                    
                  </xsl:for-each>
            </div>
            </xsl:template>

    ---------------------------------------------

    </code>


  • XSLT for Content editor (items.xsl) is used by Summary Links ?

    I just wanted to note, one of my beloved tags "disable output escape" misfired and it messed up all the summary links webpart   on all sites. I havent investigated further. but I believe Summary links also uses the Styles library for rendering html specifically Items.xsl . WOuld be nice to customize summary link web part and give some other options.

     

     

     

  • Rounded web parts

     Heather Solomon has obviously the best branding post on her blog and here she talks about rounding web parts

    http://www.heathersolomon.com/blog/articles/brandsppart3a.aspx

     

    I use a lot of XSLT and Javascript framework to modify web part and UI elements and find it usueful to not go to photoshop for rounded corners and bit of JS CSS  let you do that without image files..

     

    here is a post of using Nifty corners as alternate for rounded webparts and other UI elements

    http://cakriwut.wordpress.com/2006/11/02/moss-2007-rounded-web-part-a-nifty-corners-cube-hacks/

     

    is it efficient.. obliviously not  

  • Hide Open in windows Explorer options from Action menu

    I was looking for JavaScript to hide this "Open in Windows Explorer" for document library. I found quite a few posts with javascript, which I tried and no success. Then I went back to my ideal JavaScript framework J query( Yes I dont like learning all script details when I got J query's accessibility functions) anyway still no luck and then I found this post about hiding "upload Single Documents" options

    http://asadewa.wordpress.com/2008/02/23/removing-single-file-upload-menu-from-document-library-toolbar-moss-2007/

    And I figured the problem I had with my code. I was not adding the script during the onload event. Anyway below is the modfied code to use for hiding "open in Windows Explorer" and also using spBodyOnLoadFunctionNames  to push Function for onLoad event. 

    <script> 

     function GetElementByText(tagName, title)
        {
            var a = document.getElementsByTagName(tagName);

            for (var i=0; i < a.length; i++)
            {
                if (aIdea.text)
                {
                    if (aIdea.text === title)
                    {
                        return aIdea;
                    }
                }
            }

            return null;
        }
    function hideWinExp()
    {
     var o = GetElementByText("ie:menuitem","Open with Windows Explorer");
                if (o)
                {
                    o.disabled = true;
                }
    }
    _spBodyOnLoadFunctionNames.push("hideWinExp");

    </script>
     

    Note :

    replace  

    Idea =  [  i  ]  no spaces or copy it into text file

  • Web 2.0 Experience !=MOSS 2007 Experience ................where is the beef?

    like the Koreans protesting against ban US beef imports I am protesting against the non inclusion of Open source Web 2.0 concepts within MOSS

    Anyway I do think that the timing of release of Moss 2007 and impact of Web 2.0 has lot to do with MOSS 2007 success. Especially with rise in social networking sites on Web , an Internal social networking site for a company wasn't that far fetched an Idea and  MOSS helped bringing team collaboration and integration of various office components within a company as a reasonable possibility.

     Saying that, there still lies wide range of discrepancies with MOSS and Web 2.0 experience.The point that always is missed with MOSS development is the emergence of JavaScript and how Share point lacks these advanced UI presentation initiatives and rich Web Clients. Altough there has been a tremendous progress in terms of UI development when you take into account how SPS or WSS 2003 were, still it is not the same when it comes to comparing latest trends and MOSS initiatives. This results in distortion in end users web experience. A large part of the problem is its dependence on Microsoft's active x controls and convoluted Javascripts which have never been easy enough to understand.This also affects the large UI developers comminity who have been using these JavaScripts for different technologies like ROR, PHP and other sites, Even thought Silver light and other apps willdominate future UI development, as a developer I would like to see bridging gap between various Microsoft products and open source project atleast in terms of implementation and learning. Which brings to my next point of Secluded Microsoft Universe.  The important phenomena, with Web 2.0 technologies, has been the whole loosely coupled concept or SOA however you want to put it. I prefer Loosely coupled since it encompasses a broader range of concepts. This primarily has to do with introduction of rest api's and rest web services and allowing deep integration of various technologies and widget development. Accessing data hasn't been so much fun and so right for long (FLikr API's) , MOSS has no such component which embraces this mode of universal integration.

    I am trying to persue my personal development in this direction and hope it is good starting point.

    next Post JQuery and MOSS

  • Compression Javascript

    I was looking at performance issues on MOSS and realized Core.js and Ow.js are quite huge files to be downloaded each and every time. Then  I realised these files have been compressed OOB, I just compressed them using JSMin, I need to test it out and will post my results later. I am sure it wont drastically change the performance but this is 101 of best practices and might be quite useful for internet facing application.

     

    Anyway will post some results later  

  • SPFieldDateTime Internal names and Default Values

    Using code creating Fields is not something new. I had such a similar work to be carried out but this time I was explicitly assigning different Internal name and Display name.

    Rightly so Sharepoint provides us with a method for creating field for a list.

    splist.Fields.CreateNewField(SPFieldType.DateTime.ToString(), "Displayname"); 

    spField.Title  ( another property to assign display name)

    since  spField.InternalName is a read only field. SharePoint has another property to assign internal name

    spField.StaticName  ( Seriously beats me). Anyway surprisingly  You cannot approach this in a one Step process.

    In the end when you call SPField.Update() and splist.Update() with different combinations of StaticName and Title, I both InternalName or DisplayName will be set to one name either Display name or Internal name.

    Thats when I realized the code has to do exactly what a end user does (2 Step approach)

    1 Create a Field with Internal name

    2. Update the field's Title value.

    So here is the code for new Date time Field with different internal name and display name:

     

                             SPFieldDateTime spDateField = (SPFieldDateTime)splist.Fields.CreateNewField(SPFieldType.DateTime.ToString(), "InternalName");
                            spDateField.DisplayFormat = SPDateTimeFieldFormatType.DateTime;
                            spDateField.ShowInViewForms = true;
                            spDateField.DefaultValue = "[today]";       // This assigns Default value today to datetime
                            splist.Fields.Add(spDateField);
                            splist.Update();

                            SPField fld = splist.Fields.GetFieldByInternalName("InternalName");
                            fld.Title = GetColumnTitle(properties);

                            fld.Update();
                            splist.Update();

     

     Date Time properties such as display format is set using following line :

    spDateField.DisplayFormat = SPDateTimeFieldFormatType.DateTime;
             
    Assigning default value of Today is set using a string property value "[today]"                   

         spDateField.DefaultValue = "[today]";    

     

  • SPGridview and Ajax capabilties and Accessing Custom Property

    I started working on SPGridView for one my new Requirement and as you would predict apparently not a straight forward if you are planing to use  the feature you are seeing implemented in a share point list. I am still curious about different rendering  they are doing using SPGRIDview for list . The different style rendering Table , Preview mode and still allow filtering and sorting .

     Anyway coming back to topic SPGridView, Here are good starting points for anyway whose trying to display random list of data in a Grid.

    http://blogs.msdn.com/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx

    http://www.sharepointblogs.com/bobsbonanza/archive/2007/07/02/filtering-with-spgridview.aspx

     

    I am working on custom data from list which needs to be displayed in a grid format, different status coloring and displaying the existing functionalities like Filtering and Sorting like in Share point ( ajax way ).

    I started my development using articles above to display Grid and filtering article introduced me to Ajax capabilties for SPGridView which is much easier easier from using AjaxPro.net dll way, which btw I have worked with in SPS 2003.

    Here you are using ObjectDataSource  which is a control added to page's Controls along with your SPGridView.  The filtering works fine. Although I couldn't find any easier way of working with multiple level (cascaded ) filtering I can live with it for now.

    Here are few additional issues or work around I would like to mention,   

    1>HTML BoundColumns ( for displaying any control or text within) This is totally GRidView (.net 2.0 ) or SPGridView :

    GridView lets you use bound columns and for custom Data Table like I am developing I find it is easier to use Bound Column with html rendering. This way you can add any HTML tags in your data and it will render it accordingly. It easier because you dont mess with the control and add pre determined Img Column or anything depending on the data it will render the columns accordingly. IF i want an Image to be displayed I can add an <img> tag in my data field and it will display the img in the Grid.

     eg:

    SPGridView spGdVw = new SPGridView();

    BoundField col = new BoundField();

    col.HtmlEncode =false;

    col.DataField ="Custom";

    spGDVw.Columns.Add(col);

     

    // Your custom datatable will have a column called Custom;

     

    foreach(DataRow dr in dt.Rows)

    {

     dr["Custom"] = string.Format("<a href ='{0}'> <img src='{1}' /> </a> ","hyperlink url", "img url");

     It will display the linked Img in the column you specified.

     

    2.  Handling non Static data or  properties with Ajaxial Calls  of SPGridView

     I  was working on a web part and had custom properties for configuration, like list I am supposed to read data from etc. SPGridView works fine so easy to implement when you follow the articles above correctly. You are trying to create real world solution and now what. Filtering works fine ??  Actually once you get to implementing it, You notice only the default values of your Custom Properties are being read instead of the assigned ones and this is not problem with SPGridView it is the Ajax implementation, there is no context of current Instance. It has been a problem with AjaxPro.net dll web methods too. So there is no blaming of SPgridview.

    I actually wanted the properties to be read, So what were my options ??

    1> Use static variables to assign the custom properties values on intiailization and on Ajax call back use the values. But this doesnt solve the problem because there is just one instance of the static variable for the Class and this means if I have 2 instances of my web part on different pages, then I will be using the static variable with different propety values and at some point they would break the code. So I chose my 2nd approach

    2>  Get the object instance of the web part from the current page and Reassign properties, from current page. I could have used view state too. I just wanted to make sure I am reading right ones.

    Here is a code snippet for the Reading in the values from custom properties to use them in your call back method.

     

    SpWeb  spWeb = SPContext.Current.Web ;

    SPFile spFile = spWeb.GetFile(spWeb.Url + "/default.aspx");

    "Your Web Part instance "  

    TestWebPart   TestWp; 

    SPLimitedWebPartManager parts = spFile.GetLimitedWebPartManager(Personalization.Shared);

    foreach(WebPart wp in parts)

    {

     if(!(wp.Hidden)&&!(wp.IsClosed)&& wp is TestWebPart )

    {   TestWp = wp as TestWebPart;

    break;} 

    //Reassign your properties;

     

    sCustomProp = TestWp.CustomProperty................

     ...

    What it does is get instance of the web part from current page and Read its properties again; Yes!  but stil ldoesnt solve the entire problem here. What if there are 2 instances on same web part on same page. I have no clue may be an XML file for reading properties stored in SPList. for each instance of web part.


     

     

     


     

     

     

     

     

  • SPField (column) Field Name, Title and internal Names and Spaces between them

     I have been working with Share Point and MOSS for sometime as a developer and hate the confusion  with Title, Internal Name  for SPField (Column) for a list and development effort going being it.  I personally, if start building a site from scratch make sure there are absoulutely no spaces for any of my fields list name.  I later change the field names editing them according to given requirement.  Any developer who has worked with CAML queries and API's accessing list knows what  I am talking about.

    Column Name is the name with which you create the column (field ) and no matter how many times you change it, It remains the same. 

     
    This especially occurs when there is some kind of custom development within Share point (Custom list definition  templates, Web parts or Custom Field types). Usually all your development work is catered or intended to build something, which will meet all the needs and in fact be generic to quite an extent and thats where customizable web parts using Tool parts or Customizable Custom field type come in to play.

    Reason I am mentioning Configuration is because thats the point where you interact with Users configuring and your code deciphers everything and  Boom! it works. Here are the different scenarios I am talking about.

    I am creating a column called "Company Name" 


    After Renaming the column CAML Query Tool

    Suppose you are working on a Web Part where you want users to Pick a list and few Columns and you do some custom logic and  render the Data.

    Column NAME  :

    1> Users say Column Name it means SPField.Title ( title could be  "ABC Company Name "  but Column name would be "CompanyName")

    2> In you code if you are using  Splist.Fields[" Field Name"] or  listItem["Field Name"]  you would be using the Internal Column Name

     E.G:
    Title = "Company Name"   ColumnName(internal name) =  "Comp Name"     You would use  listItem["Comp Name"]

    3> Caml Queries:

    You are using some logic and you don't need to traverse through the entire list items and  you decide to use "CAML Query"

    Spquery Object.  Here it gets tricky because you do use the internal name in your Code, if there are any Spaces you got to replace them by "_x0020_"

    E.G :

      spQuery.ViewFields= string.Format("<FieldRef Name='{0}'/>", field.Replace("", "x0020"));

    So if there wasn't any space in the field internal name there was no need to replace.
     

    Even though there are just 3 or may be bit more scenarios and which a developer can  code to handle them, I feel there is lot of development effort going behind it, If an environment is created where are these scenarios are taken care of on creation of list (as mentioned above ) then it would reduce the development time drastically. As in , you know in all you list there is no column created with a Space in them, why would ever worry about those scenarios during development and think about configuration scenarios where you are making user pick "title" for a column but in you code you got one variable for each field for Internal name and other variable for each field to store CAML field name. May be I am just going way overboard and hoping to have a perfect share point world , but hey! hope is all we got 

    So here the rule I follow :

    1. Whenever you are creating a a list or fields ALWAYS assume you have to do some custom development work on that list so you better follow the rule  

    2. All sites, lists fields (any god damn thing) on creation should not have a space in  between.

    3. After creation of site, list and field with your developer friendly name. Rename or assign title according to your Requirements.

    4. Make sure you develop something against that list. :)
     


Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts