Thursday, January 19, 2012

How to: Add a Content Type to a SharePoint List using C#

Create a SharePoint 2010 Project

In this task, you create an empty SharePoint 2010 project in Microsoft Visual Studio 2010.
To create the SharePoint project
  1. To start Visual Studio 2010, click the Start Menu, click All Programs, click Microsoft Visual Studio 2010, and then click Microsoft Visual Studio 2010.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog window, in the Installed Templates section, click Visual C#, click SharePoint, and then click2010.
  4. Select Empty SharePoint Project from the project items.
  5. In the Name box, type CreateContentType and then click OK.
  6. In the SharePoint Customization Wizard, type the local Web site that you want to use for this exercise (such as http://localhost/SampleWebSite).
  7. For the trust level, select Deploy as a farm solution and then click Finish.

Create a Content Type

Saturday, January 14, 2012

SharePoint Page Types

There are two primary types of pages in Microsoft SharePoint Foundation.

They are:

  • Site pages and
  • Application pages.

Site pages: 

Site pages are pages that are created, edited, and customized by end users. They are primarily used for the content in a site. Site pages come in two types—

  • A standard page and
  • A Web Parts page.

A standard page contains text, images, Web Parts, and other elements. A Web Parts page contains Web Parts in Web Part zones. They have a predefined layout that uses Web Part zones. Both types of site pages are edited using a Web browser or Microsoft SharePoint Designer.

Site pages are provisioned from a template page that is stored on the file system of the front-end Web server. When a site is provisioned, SharePoint Foundation creates a pointer to the instance of the page template on the file system. This allows SharePoint Foundation to avoid repeatedly creating copies of the pages, which are provisioned each time a site is created.

When a user customizes a site page, the template for the page is then stored in the content database. The page is retrieved from the content database every time it is requested by a user. A customized page can, however, be reset to the original template page through the Web browser or a tool such as SharePoint Designer.

Customized site pages cannot contain in-line server code. The set of controls that are allowed to run on the page is governed by the safe controls list in the<Drive>:\inetpub\wwwroot\wss\VirtualDirectories\<port number>\web.config file. It is a recommended best practice to avoid using server-side code on site pages when developing site definitions. If a user later edits or modifies that page, the code will no longer run.

The following are general rules for using server-side code on a site page.

  • If the page is un customized, server-side code is supported on the page.

  • If the page is customized, server-side code does not run, and the page does not render. This includes the code-behind for the page itself.

 

Application Pages:

Application pages are used to support application implementations in SharePoint Foundation. Application pages are stored on the file system of the front-end Web server in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LAYOUTS directory and exist for every site in a Web application. This folder is mapped to an Internet Information Services (IIS) virtual directory called _layouts. Every site and subsite will have access to the application pages by using the _layouts virtual directory. For example, http://myserver/_layouts/settings.aspx and http://myserver/subsite/_layouts/settings.aspx access the same application page on the front-end Web server unlike site pages, which are an instance for the specified site.

Application pages are not subject to the same restrictions as site pages. They allow in-line code without restriction. They cannot, however, use dynamic Web Parts or Web Part zones or be modified using SharePoint Designer. Modifying the default application pages is not supported in SharePoint Foundation. Custom application pages can be added to a subdirectory inside the _layouts folder.

Blogger Labels: SharePoint,Page,Types,Microsoft,Foundation,Site,Application,users,Parts,text,Part,zones,layout,Both,Designer,template,system,server,pointer,instance,user,database,tool,Drive,VirtualDirectories,port,definitions,Pages,implementations,ProgramFiles,Common,Files,extensions,LAYOUTS,folder,Internet,Information,Services,_layouts,example,settings,restrictions,restriction,Custom,subdirectory,browser,subsite,myserver,aspx

Programmatically launch Debugger in a remote machine


ConnectionOptions options = new ConnectionOptions();
 ManagementScope scope = new ManagementScope("\\\\machine1\\root\\cimv2", options);
 scope.Connect();

 ObjectQuery oQuery = new ObjectQuery("Select * from Win32_Process where Name Like 'ConsoleApp%'");
 //Execute the query
 ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(scope,oQuery);

 //Get the results
 ManagementObjectCollection objReturnCollection = objSearcher.Get();

 foreach (ManagementObject oReturn in objReturnCollection)
 {
 if (oReturn["Name"].ToString().Equals("ConsoleApplication1.exe"))
 {
 object outparams = oReturn.InvokeMethod("AttachDebugger", null);
 }
 }

Friday, January 13, 2012

Implementing Singleton in C#

Singleton class in oops is a facility that provide us an option to define a class to have single instance throughout the program lifetime, it also help us to have a global access point.
How to implement singleton class in c#:

using System;

public class Singlton

{

private static Singleton instance;

private singleton(){}

public static Singleton instance

{

        get

        {

               if(instance ==null)

               {

                    instance =new Singleton();                      

//Checks if the instance has already been created, 

//if yes will return the already created instance else,

                    //will create a new instance of the Singleton Class.

               }

               return instance;

        }

}

}




Tuesday, January 10, 2012

Static Classes and Static Class Members

A static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself. For example, if you have a static class that is named UtilityClass that has a public method named MethodA, you call the method as shown in the following example

UtilityClass.MethodA();

 

A static class can be used as a convenient container for sets of methods that just operate on input parameters and do not have to get or set any internal instance fields. For example, in the .NET Framework Class Library, the static System.Math class contains methods that perform mathematical operations, without any requirement to store or retrieve data that is unique to a particular instance of the Math class. That is, you apply the members of the class by specifying the class name and the method name, as shown in the following example.


 

double dub = -3.14;
Console.WriteLine(Math.Abs(dub));
Console.WriteLine(Math.Floor(dub));
Console.WriteLine(Math.Round(Math.Abs(dub)));

// Output:
// 3.14
// -4
// 3

The following list provides the main features of a static class:




    1. Contains only static members.



    2. Cannot be instantiated.



    3. Is sealed.



    4. Cannot contain Instance Constructors.


 


 


Programmatically launch Debugger in a remote machine

Flickr Tags: ,

ConnectionOptions options = new ConnectionOptions();
ManagementScope scope = new ManagementScope(\\ComputerAdd\\path\\,
options);
scope.Connect();
ObjectQuery oQuery = new ObjectQuery("Select * from Win32_Process where Name
Like 'ConsoleApp%'"
);
//Execute the query
ManagementObjectSearcher objSearcher =
newManagementObjectSearcher(scope,oQuery);
//Get the results
ManagementObjectCollection objReturnCollection = objSearcher.Get();
foreach (ManagementObject oReturn in objReturnCollection)
{
if (oReturn["Name"].ToString().Equals("ConsoleApplication1.exe"))
{
object outparams = oReturn.InvokeMethod("AttachDebugger", null);
}
}

What is the difference between const and static readonly?


The difference is that the value of a static readonly field is set at run time, and can thus be modified by the containing class, whereas the value of a const field is set to a compile time constant.
In the static readonly case, the containing class is allowed to modify it only
  • in the variable declaration (through a variable initializer)
  • in the static constructor (instance constructors, if it's not static)
static readonly is typically used if the type of the field is not allowed in a const declaration, or when the value is not known at compile time.
Instance readonly fields are also allowed. 
Remember that for reference types, in both cases (static and instance) the readonly modifier only prevents you from assigning a new reference to the field.  It specifically does not make immutable the object pointed to by the reference.
    class Program
    {
        public static readonly Test test = new Test();

        static void Main(string[] args)
        {
            test.Name = "Program";

            test = new Test();  // Error:      A static readonly field cannot be assigned to (except in a static constructor or a variable initializer) 

        }
    }

    class Test
    {
        public string Name;
    }

On the other hand, if Test were a value type, then assignment to test.Name would be an error.

Sunday, January 8, 2012

About Windows Phone 7

Windows Phone 7 Terminology


  • Accelerometer. A device capability that measures acceleration in three planes, and the direction of the force of gravity that indicates the attitude of the device. Can be used to detect movement, including gestures such as shaking the device.
  • Advanced Encryption Standard (AES). A symmetric encryption algorithm available on Windows Phone 7 that can be used to encrypt data.

Tuesday, January 3, 2012

Featured Posts

Learn how to install Apache, MySQL and PHP on Ubuntu. Complete LAMP stack installation guide with one-shot commands, PHP testing and php-opcache troubleshooting

How to Install LAMP Stack on Ubuntu | Complete Guide UBUNTU • LINUX • SERVER • PHP ...