Realizing Results

my personal notes on C#, SharePoint and object oriented programming

  Home  |   Contact  |   Syndication    |   Login
  7 Posts | 0 Stories | 2 Comments | 0 Trackbacks

News

Archives

About Me

Monday, November 08, 2010 #

Creating a Custom Site Definition:

·         http://msdn.microsoft.com/en-us/library/ms474369.aspx

·         http://msdn.microsoft.com/en-us/library/ms454677.aspx

Adding Pages to a Site Definition:

Each page in the onet.xml is defined in a <Module> tag.

For e.g.

 <ModuleName="Home"Url="$Resources:cmscore,List_Pages_UrlName;"Path="">

Similarly if we want to add more than one page we can add the same in module tag.

For e.g.

<ModuleName="Home"Url="$Resources:cmscore,List_Pages_UrlName;"Path="">

All these <module> tags are defined under <Modules> tag.

Remember there can be a number of <module> tags but only ONE <Modules> tag.

Now each site made using this site structure will have three pages created automatically.

 

The <Module Tag>

<ModuleName="EventOverview"   Url="$Resources:cmscore,List_Pages_UrlName;"Path="">

 <FileUrl="EventOverview.aspx"Type="GhostableInLibrary" >

<PropertyName="Title"     Value="$Resources:cmscore,IPPT_HomeSMSPWAePage_Title;" />

<PropertyName="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/EventsOverviewLayout.aspx, ~SiteCollection/_catalogs/masterpage/EventsOverviewLayout.aspx" />

 </File>

</Module>

·  Each module tag defines the page that will be created.

·  The file tag gives the url of the page.( make a copy of default.aspx and rename it as EventOverview.aspx in the TestStructure Folder)

·  Type=”GhostableInLibrary” will tell sharepoint to create an instance of this particular page in the pages library of the corresponding site.

·  Various properties can also be set using the <Property> tag. For eg we can specify the layout which this page should refer to while it gets created.(in this case it is referring to a custom layout EventsOverviewLayout.aspx)

·  (how to refer layouts is discussed later)

·  Like this as many modules can be added according to the requirement.

·  The <Modules> tag will also get registered in the <Configuration> tag of Onet.xml  

·  For e.g.

              The <configuration> Tag

<configuration>

            <Modules>

                <ModuleName="LoginPage" />

                <ModuleName="Images" />

                <ModuleName="Home" />

                    <ModuleName="SMSPWAHome" />        

            </Modules>

          </Configuration>

 

Referring Custom Layouts to the Pages: 

Layout pages are present in the /_catalogs/MasterPage of the site!

We can define our own custom layout page in the master page gallery.

By default MOSS does not allow the subsite to inherit the page layout from the parent site.

 To enable this we can go to

“Parent Site “> Site Actions > Site Settings > Modify All Site Settings > PageLayout and Site Template Settings >

Here we can set the subsite to inherit templates and pagelayouts from the parent site itself.

 

·         In the Onet.xml we need to give reference of the Custom Layout for a page.

In the < module > tag, set the property to refer the layout.

<FileUrl="default.aspx"Type="GhostableInLibrary" >

<PropertyName="Title"Value="$Resources:cmscore,IPPT_HomeSMSPWAePage_Title;" />

<PropertyName="PublishingPageLayout"Value="~SiteCollection/_catalogs/masterpage/CustomLayout.aspx, ~SiteCollection/_catalogs/masterpage/CustomLayout.aspx" />

</File>

 

After finishing with this, the user can just reset the IIS and create a site. The site will be created according to the desired structure and the layout!

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Friday, October 29, 2010 #

Lets have a look what is REST?
REST (Representational State Transfer)- An Architectural Style, Not a Standard
REST is not a standard. You will not see the W3C putting out a REST specification. You will not see IBM or Microsoft or Sun selling a REST developer's toolkit. Why? Because REST is just an architectural style. You can't bottle up that style. You can only understand it, and design your Web services in that style. (Analogous to the client-server architectural style. There is no client-server standard.)
While REST is not a standard, it does use standards:
·         HTTP
·         URL
·         XML/HTML/GIF/JPEG/etc (Resource Representations)
·         text/xml, text/html, image/gif, image/jpeg, etc (MIME Types)
Principles of REST Web Service Design
·         1. The key to creating Web Services in a REST network (i.e., the Web) is to identify all of the conceptual entities that you wish to expose as services. Above we saw some examples of resources: parts list, detailed part data, purchase order.
·         2. Create a URL to each resource. The resources should be nouns, not verbs. For example, do not use this:
·         http://www.parts-depot.com/parts/getPart?id=00345
·         Note the verb, get Part. Instead, use a noun:
·         http://www.parts-depot.com/parts/00345
·         3. Categorize your resources according to whether clients can just receive a representation of the resource, or whether clients can modify (add to) the resource. For the former, make those resources accessible using an HTTP GET. For the later, make those resources accessible using HTTP POST, PUT, and/or DELETE.
·         4. All resources accessible via HTTP GET should be side-effect free. That is, the resource should just return a representation of the resource. Invoking the resource should not result in modifying the resource.
·         5. No man/woman is an island. Likewise, no representation should be an island. In other words, put hyperlinks within resource representations to enable clients to drill down for more information, and/or to obtain related information.
·         6. Design to reveal data gradually. Don't reveal everything in a single response document. Provide hyperlinks to obtain more details.
·         7. Specify the format of response data using a schema (DTD, W3C Schema, RelaxNG, or Schematron). For those services that require a POST or PUT to it, also provide a schema to specify the format of the response.
·         8. Describe how your services are to be invoked using either a WSDL document, or simply an HTML document.
 
For more information checkout this link:-
 
http://www.xfront.com/REST-Web-Services.html
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, September 21, 2010 #

Features

A SharePoint feature is a collection of SharePoint elements that can help to accomplish a particular functionality. Features reduce the complexity involved in making simple site customizations, and are robust when upgrades are applied to a deployment.Definition of a site or a template can be easily transformed by simply toggling a particular Feature on or off in the user interface.

 

For example :- Publishing features of MOSS provide all the required functionality like publishing layouts, lists, pages library, style library etc.

Features make it possible to activate or deactivate functionality.

 

·         Features provide the following capabilities

·         Pluggable behavior for installing or uninstalling Features within a deployment.

·         Pluggable behavior for activating or deactivating features at a given scope.

·         A scoped property bag for storing data required by Features within its scope.

Feature Implementation

All the features in MOSS should be at [WSS]\Template\Features folder.

Each Features sub-folder must include a Feature.xml file that defines the base properties of a Feature and lists of the element manifests associated with it. Element manifests are XML files whose top level <Elements> tag contains definitions for elements that support the Feature.

 

Feature.xml:  Following are the main tags of Feature.xml

 

 Attribute

Required

Description    

Id

Yes

Contains the globally unique identifier (GUID) for the Feature.

Title

No

Title of feature

Description

No

Description of the feature.

Version

No

Version of feature

Scope

Yes

Feature can be scoped at following level.

·          Farm

·          Web Application

·          Site: - Site collection level

·          Web: - Web-Site

Hidden

No

True: - To hide it from UI (Site features)

False: - To display in UI (site features)

ReceiverAssembly

No

Specifies the strong name of the signed assembly located in the global assembly cache from which to load a receiver to handle Feature events

ReceiverClass

No

Specifies the class that implements the Feature event processor.

 Element Manifests: It contains references to element manifests and element files that contain definitions for the Feature elements.

Element Manifest: - Specifies a file that contains a definition for a feature element.

  

Attribute

Required

Description

Location

Yes

Specifies the relative file path to the root element manifest file.

 

ElementFile:  Specifies a support file required for the Feature.

  

Attribute

Required

Description

Location

Yes

Specifies the relative file path to the support file for the feature.

 

Properties: It contains the default values for feature properties.

 

Element manifest file: Following are the element types for feature.

 

Element

Description

ListTemplate

Contains a list definition

ListInstance

Create a List Instance based on some already exist list template.

Field

For creating site columns

Module

Contains the set of files with which to provision sites.

FeatureSiteTemplateAssociation

To associate new Features and functionality with existing site definitions or site templates so that, when sites are provisioned, the Features are automatically included in provisioning.

Receiver

Contains an item event receiver registration.

ContentType

Schema definition which can be reuse and apply to multiple list definition.

 

Install features:  

Installation makes aware the entire front-end web server about the feature definition. Installed Feature will display the Features in the list of available Features.

Before installing feature sub-folder should be present in [WSS]\Template\Features

Where generally

[WSS] = C:\Program Files\Common Files\Microsoft Shared\web server extension\12\TEMPLATE\Feature

stsadm –o installfeature –name <Name of feature>

 

Uninstall Feature

stsadm –o installfeature –name <Name of feature>

 

Feature Activation

To use the functionality associated with Feature, it must be activated at required scope.

Suppose a feature is developed for creating a list instance based on default custom list at Web Scope. List instance will be created only if the feature is activated at the required web site.

 

A Feature can be activated in following ways

 

Through the Site Settings Web pages: - Go to “Site settings ->Site Features” to activate a feature.

 

The STSADM command line:-

stsadm –o activatefeature –name <Folder name >

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Thursday, September 16, 2010 #

HTML Table based Charts:

The technique used below is to generate line charts with the help of html tables and 3d images. It draws the table calibrate a 3d image to fit in the row as per the given x\y axis value. Hence become very lightweight and supported on any .net framework\ other platforms. Below is the sample screen shot

Please see the complete details about the code at http://manishsati.blogspot.com/2010/04/html-table-based-chart-control-in.html

 
public partial class SMDashboardChart : System.Web.UI.UserControl
    {
        private String _sXAxisTitle="X-Axis Title";
        private String _sChartTitle="Chart Title";
        private int _ichartWidth = 500;
        private String[] _sXAxisValues;
        private int[] _iYAxisValues;
        private int _iColumnWidth = 30;
        private string strErrMsg = "Data is not available to display on the chart";
       
        public string ErrorMessage
        {
            set { this.strErrMsg = value; }
        }
        public int Chartwidth
        {
            get { return _ichartWidth; }
            set { _ichartWidth = value; }
        }
 
        public int ColumnWidth
        {
            get { return _iColumnWidth; }
            set { _iColumnWidth = value; }
        }
        public int[] YAxisValues
        {
            get { return _iYAxisValues; }
            set { _iYAxisValues = value; }
        }
 
        public String[] XAxisItems
        {
            get { return _sXAxisValues; }
            set { _sXAxisValues = value; }
        }
 
        public String XAxisTitle
        {
            get { return _sXAxisTitle; }
            set { _sXAxisTitle = value; }
        }
 
        public String ChartTitle
        {
            get { return _sChartTitle; }
            set { _sChartTitle = value; }
        }
 
        ///<summary>
        /// draw the graph
        ///</summary>
        public void DrawGraph()
        {
            // As long as we have values to display, do so
            if (_iYAxisValues != null)
            {
                // Color array
                String[] sColor = new String[5];
                sColor[0] = "Images/rowbk-B.JPG";
                sColor[1] = "Images/rowbk-G.JPG";
                sColor[2] = "Images/rowbk-P.JPG";
                sColor[3] = "Images/rowbk-R.JPG";
                sColor[4] = "Images/rowbk-y.JPG";
               
                // Initialize the color category
                int iColor = 0;
                // Get the largest value from the available items
                int iMaxVal = 0;
                for (int i = 0; i < _iYAxisValues.Length; i++)
                {
                    if (_iYAxisValues[i] > iMaxVal)
                        iMaxVal = _iYAxisValues[i];
 
                }
                // Take the user-provided maximum width of the chart, and divide it by the
                // largest value in our valueset to obtain the modifier
                //add one in the result if imod becomes zero to aviod divison by zero
                if (iMaxVal > 0)
                {
                    int iMod = Math.Abs(_ichartWidth / iMaxVal) ;
                    // This will be the string holder for our actual bars.
                    string sOut = "";
                    // Render a bar for each item
                    for (int i = 0; i < _iYAxisValues.Length; i++)
                    {
 
                        // Only display this item if we have a value to display
                        if (_iYAxisValues[i] >= 0)
                        {
                            sOut += "<tr><td align=right style=font-size:11px nowrap=false>" + _sXAxisValues[i] + "&nbsp;</td>";
                            //call function DRAWCOLUMN here
                            sOut += "<td class='styleBG'>" + DrawColumn(_iYAxisValues[i], iMaxVal, iMod, sColor[iColor], _sXAxisValues[i]) +
                                    "</td></tr><tr><td height=10></td><td height=10></td></tr>";
                            iColor++;
                            // If we have reached the end of our color array, start over
                            if (iColor > 4) iColor = 0;
                        }
                    }
 
                    // Place the rendered string in the appropriate label
                    div1.InnerHtml = "<table class='ChartTable' align =center cellpadding=5><tr><td align=center style=font-size:13px>" + _sChartTitle +"<table cellspacing=0 cellpadding=0 >" + sOut + "</table></td></tr></table></td></tr>" +"<tr><td colspan=2 align=center style=font-size:13px>" + _sXAxisTitle + "</td></tr><TR><TD>&nbsp;</TD></TR></table>";   
                }
                else
                {
 
                    div1.InnerHtml = "<TABLE class ='ChartTable'><TR><TD align=center style=font-size:11px>" +
                        this.strErrMsg + "</TD></TR></TABLE>";
 
                }
 
            }
        }
        ///<summary>
        /// draws the columns of the chart
        ///</summary>
        ///<param name="iVal">value of the column</param>
        ///<param name="iMaxVal">maxumum value in the dataset</param>
        ///<param name="iMod">modifier value</param>
        ///<param name="sColor">path of the various images</param>
        ///<returns></returns>
        private String DrawColumn(int iVal, int iMaxVal, int iMod, String sColor, string yval)
        {
            if (iMod <= 0)
                iMod = 1;
            //get the modified width of the column
            int iWidth = iVal * iMod;
            //if modified width is greater than chart width than divide it unless the value is not less than chart width
            while (iMaxVal * iMod > _ichartWidth)
            {
                iWidth = Convert.ToInt32(iWidth / 1.5);
                iMaxVal = Convert.ToInt32(iMaxVal / 1.5);
            }
            string tooltip = iVal.ToString();
            StringBuilder sRet = new StringBuilder();
            sRet.Append("<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor=#104983>");
            sRet.Append("<img title=" + tooltip + " src='" + sColor + "' complete='complete' height=" + ColumnWidth + " width=" + iWidth + "/></td>");
            sRet.Append("<TD style=font-size:11px>" + iVal + "</TD><TR></table>");
            // sRet.Append("<TR></table>");
            return sRet.ToString();
        }

    }

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, August 31, 2010 #

Many times we see any of these two different convention used by different programmers for null checks. Even have seen many seasoned java professional who used the first form and argued that X!=null may hit the performance so one should use null!=X, but if you go through the c# language specification there is no such difference as such in both the forms and  are translated to x.HasValue during compilation. below is section as explained in CLS

From C# language Specification:

Section 14.9.9 Equality operators and null
The == and != operators permit one operand to be a value of a nullable type and the other to have the null type (§11.2.7), even if no predefined or user-defined operator (in unlifted or lifted form) exists for the operation.

For an operation of one of the forms
x == null null == x x != null null != x where x is an expression of a nullable type,

if operator overload resolution (§14.2.4) fails to find an applicable operator, the result is instead computed from the HasValue property of x. Specifically, the first two forms are translated into !x.HasValue, and last two forms are translated into x.HasValue.

but still i was not so convinced with the fact and wanted to test actual execution time for these two. the below is the sample program for the test i used

 class TestClass
    {
        public static void Main()
        {
            TestClass x1 = new TestClass();
            for (int i = 0; i < 10; i++)
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                Console.WriteLine("{0}, {1}, {2}", "x1 != null", x1 != null, sw.ElapsedTicks);
                sw.Restart();
                Console.WriteLine("{0}, {1}, {2}", "null != x1", null != x1, sw.ElapsedTicks);
                sw.Restart();
                Console.WriteLine("{0}, {1}, {2}", "x1 == null", x1 == null, sw.ElapsedTicks);
                sw.Restart();
                Console.WriteLine("{0}, {1}, {2}", "null == x1", null == x1, sw.ElapsedTicks);
                sw.Stop();
                Console.WriteLine();
            }
            Console.ReadLine();
        }
    }

and the output of the program is below except for the first iteration

x1 != null, True, 906
null != x1, True, 787
x1 == null, False, 860
null == x1, False, 765

x1 != null, True, 869
null != x1, True, 783
x1 == null, False, 869
null == x1, False, 836

x1 != null, True, 841
null != x1, True, 824
x1 == null, False, 899
null == x1, False, 806

x1 != null, True, 845
null != x1, True, 832
x1 == null, False, 912
null == x1, False, 805

x1 != null, True, 869
null != x1, True, 845
x1 == null, False, 916
null == x1, False, 832

output shows that there is marginal difference in x1 != null and null != x1 but still null != x1 behaves better than the other counterpart 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Wednesday, September 01, 2010 #

below is the code to find out the higjhlighted text in word documents in c#

public string FindHighlightedText()
{
    object missing = Type.Missing;
    Type t = System.Type.GetTypeFromProgID("Word.Application");
    Application objWord = (Application)Activator.CreateInstance(t);
    Document objDoc = objWord.Documents.Open(filepath);
    Range objRange = objDoc.Range(0, Type.Missing);
    objRange.Find.Highlight = 0;
    objRange.Find.Forward = true;
    do
    {
        if (objRange.HighlightColorIndex == WdColorIndex.wdYellow)
        {

            objRange.HighlightColorIndex = WdColorIndex.wdRed;
            objRange.Font.ColorIndex = WdColorIndex.wdBlue;
        }
        int intPosition = objRange.End;
        objRange.Start = intPosition;
    } while (objRange.Find.Execute("", missing, missing, missing, missing, missing, true,
        missing, missing, missing, missing, missing, missing, missing, missing));

    objWord.Quit(true, Type.Missing, Type.Missing);
    return "true";
}

don't forget to reference Microsoft.office.interop.word DLL before you use this code

 

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, August 31, 2010 #

below is the code snippet on how to update a field in sharepoint list which contains multiple chioce value

using(SPWeb oWebsite = SPContext.Current.Site.AllWebs["Site_Name"])
{
  SPList oList = oWebsite.Lists["listname"];
  SPListItem oListItem = oList.Items[0];

  oListItem["columnname"] = "choice1;#chioce2;#chioce3"
  oListItem.Update();
}

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati