Posts Tagged create

SharePoint 2010: PowerShell Script to create Discussion Board / Discussion Forum

Scenario:

We need to create discussion board / discussion forum using power shell script

Resolution:

$spWeb Get-SPWeb $webURL

$listTemplate = [Microsoft.SharePoint.SPListTemplateType]::DiscussionBoard

$spWeb.Lists.Add(“Discussion Forum”, “Custom List”, [int]$listTemplate)

Thanks to my friend Abdur Raheem 

Comments (1)

SharePoint / MOSS: Creating Site Programmatically

I was interested in creating MOSS 2007 site using code. I end up with the following code:

 

SPSite oSiteCollection = new SPSite(http://servername/SiteDirectory”);            

SPWeb oWebSite = oSiteCollection.OpenWeb();

SPWebCollection oSitesCollection = oWebSite.Webs;

SPWeb newWebSite = oSitesCollection.Add(“abc”, “Document Library                 Template”, “This is site created through code.”, 1033, “STS#2”, true, false);

 

We will only explore SPWebCollection Add Method. The Add method has following parameters:

 

strWebUrl:

 

A string that contains the new Web site URL relative to the root Web site in the site collection. For example, to create a Web site at http://MyServer/sites/MySiteCollection/MyNewWebsite, specify MyNewWebsite, or to create a Web site one level lower at http://MyServer/sites/MySiteCollection/Website/MyNewWebsite, specify Website/MyNewWebsite.

 

strTitle

 

A string that contains the title.

 

strDescription

 

A string that contains the description.

 

nLCID

 

An unsigned 32-bit integer that specifies the locale ID. You can find a complete list of local ID at the following URL:

 

http://www.microsoft.com/globaldev/reference/lcid-all.mspx

 

We have used “1033” for English – United States.

 

strWebTemplate

 

A string that contains the name of the site definition configuration or site template. The following table shows the values for the default site definition configurations that are included in an installation of Windows SharePoint Services

 

Value

Site Definition

STS#0

Team Site

STS#1

Blank Site

STS#2

Document Workspace

MPS#0

Basic Meeting Workspace

MPS#1

Blank Meeting Workspace

MPS#2

Decision Meeting Workspace

MPS#3

Social Meeting Workspace

MPS#4

Multipage Meeting Workspace

WIKI#0

Wiki

BLOG#0

Blog

 

For more MOSS/WSS SiteTemplate codes, visit the following URLs:

 

http://mystepstones.wordpress.com/2008/02/14/sitetemplate-codes/

 

http://stevenjohnevans.co.uk/blogs/dotnet/archive/2007/11/25/standard-site-definitions-within-sharepoint-2007-moss.aspx

 

useUniquePermissions

 

true to create a subsite that does not inherit permissions from another site; otherwise, false.

 

bConvertIfThere

 

true to convert an existing folder of the same name to a SharePoint site. false to throw an exception that indicates that a URL path with the specified site name already exists.

   

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spwebcollection.aspx

Comments (6)

SharePoint 2003 to MOSS 2007 Upgrade: Database migration

Of all the three upgrade techniques, my favorite is database migration. Database migration can be defined as “Requires the server administrator to install the new version on a separate farm or separate hardware, and then manually migrate the databases into the new environment.”

 

Database Migration enables moving to new farm or new hardware while SharePoint Portal Server 2003 environment is available and is untouched by upgrade. Microsoft says that database migration is a “Complex process that requires many manual steps and a higher risk of error. Requires additional manual steps to retain original URLs for sites. Search scopes must be re-created and search settings must be reapplied. Requires new server farm, and twice the amount of SQL Server storage space”. My advise is don’t be afraid and do try.

 

These steps are done for upgrade from WSS2.0/SharePoint 2003 to WSS3.0/MOSS 2007 in a single form environment. For different architecture, you may need some more steps. The steps are under: 

·     Get ready your MOSS 2007 environment.

·     Run PreScan on SharePoint Portal Server 2003.

·     Set the content database of SharePoint Portal Server 2003 as read only.

·     Take back up of content database of SharePoint Portal Server 2003.

·     Restore back up on SQL Server attached with MOSS 2007.

·     Create web application in MOSS 2007.

·     Remove content database of the newly created web application in MOSS 2007.

·     Attach restore database with the newly created web application in MOSS 2007.

 

And that’s itJ.

 

I am not going into the details of creating MOSS 2007 environment. We will start from the second step:

 

Run PreScan on SharePoint Portal Server 2003:

 

The first step is to run PreScan.exe. For details kindly visit the following blog:

 

https://farhanfaiz.wordpress.com/2008/05/15/sharepoint-upgrade-prescanexe/

 

Set the content database of SharePoint Portal Server 2003 as read only:

The content database of SharePoint Portal Server 2003 ends with 1_SITE like Abc1_SITE.

 

The steps for setting database as read only are:

 

For SQL Server 2000

 

1.     In Microsoft® SQL Server™ Enterprise Manager, right-click the name of the database that you want to set to read-only, and then click Properties.

2.     In the Properties dialog box, click the Options tab.

3.     Under Access, select the Read-only check box, and then click OK.

 

 

For Server 2005

1.     In Microsoft SQL Server Management Studio, right-click the name of the database that you want to set to read-only, and then click Properties.

2.     In the left pane, click Options.

3.     In the right pane, under Other options, under State, next to Database Read-Only, click the down arrow, and then select True.

 

Take back up of content database of SharePoint Portal Server 2003:

 

For details kindly visit the following blog:

 

https://farhanfaiz.wordpress.com/2008/05/16/sharepoint-2003moss-2007-take-back-up-of-content-database-in-sql-server-2000-and-sql-server-2005/

 

Let the name of the back be “Portal_Site.bak”. Wait after this. The time of database backup depends upon the system power and database size.

 

 

Restore back up on SQL Server attached with MOSS 2007:

 

The first step in restoring database is to create a database in SQL Server 2005. Let the newly created database name is “Portal_Site_Restore”.

 

1.     Expand Database “Portal_Site_Restore”, right-click the database you want to restore, point to Tasks, point to Restore, and then click Database. The Restore Database dialog box appears.

2.     On the General page, the name of the restoring database appears in the To database list box.

3.     In the To a point in time text box (if using SQL Server 2005 Enterprise Edition), retain the default (Most recent possible).

4.     To specify the source and location of the backup sets to restore, click From device, and then specify the database backup path (in our case, it is “Portal_Site.bak”) in the list box.

5.     In the Select the backup sets to restore grid, select the backup path.

6.     From the options tab, select “overwrite existing database”.

7.     Specify the paths for .ldf and .mdf in the options tab.

8.     Click OK to start the restore process.

 

Wait after this. The time of restoring database depends upon the system power and database size.

 

 

Create web application in MOSS 2007

 

In the SharePoint Central Administration, move to “Application Management” and click on “Create or extend Web application” under “SharePoint Web Application Management”.

 

Again click on “Create Web application”. Set the settings according to your own needs (do check the name of the web application and content database. Let the name of the web application be “http://servername:1234” and the name of the content database be “WSS_Content_1234”) and click OK. Don’t create any site collection.

 

 

Remove content database of the newly created web application in MOSS 2007

 

We can do that using Central Administrator or stsadm utility. I will like to do that using stsadm. Central Administration is easy. You will be able to learn that if you know how to do it using stsadm.

 

The command for removing content database using stsadm is ‘deletecontentdb’. The description is as under:

 

stsadm.exe -o deletecontentdb

-url <URL name>

-databasename <database name>

[-databaseserver] <database server name>

 

Parameter name

Value

Required?

Description

url

A valid URL, such as http://serverame:1234

Yes

Specifies the Web application from which the content database will be detached.

databasename

A valid database name, such as “WSS_Content_1234”

Yes

Specifies the name of content database to be detached.

databaseserver

A valid database server, such as “SQLServer1”

No

Database server name to be detached.

 

A typical command will be like:

 

stsadm.exe -o deletecontentdb -databasename WSS_Content_1234 -url http://servername:1234

 

Attach restore database with the newly created web application in MOSS 2007

 

We can do that using Central Administrator or stsadm utility. I will like to do that using stsadm. Central Administration is easy. You will be able to learn that if you know how to do it using stsadm.

 

The command for removing content database using stsadm is ‘addcontentdb’. The description is as under:

 

stsadm.exe -o addcontentdb

-url <URL name>

-databasename <database name>

[-databaseserver <database server name>]

[-databaseuser <database username>]

[-databasepassword <database password>]

[-sitewarning <site warning count>]

[-sitemax <site max count>]

 

Parameter name

Value

Required?

Description

url

A valid URL 

Yes

URL of

the Web

application

to which

the content

database is

being

added.

databasename

A valid

database name

Yes

Database

name.

databaseserver

A valid

database

server name

No

Database

server

name. The

default

server

is used

if a

value

not

provided.

databaseuser

A valid user

name in the

form “domain\login”

No

Account

used for

SQL authentication. Must be

used in

conjunction

with the

database

password parameter.

databasepassword

A valid

SQL

password

No

The database

password parameter should only

be used

where Windows authentication is not

implemented.

sitewarning

A valid

integer

number,

such as

10

No

Integer number

of site

collections allowed in

the content

database

prior to

generating

a warning

event in the

Windows event log.

sitemax

A valid

integer

number,

such as

10

No

Specifies

the maximum

number of site collections allowed in

the content

database.

 A typical command will be like:

 

stsadm.exe -o addcontentdb -url http://servername:1234 –databasename Portal_Site_Restore

 

Wait after this command. The time of adding content database depends upon the system power and database size.

 

 

http://office.microsoft.com/download/afile.aspx?AssetID=AM101638521033

 

http://technet.microsoft.com/en-us/library/cc263422.aspx

 

http://technet.microsoft.com/en-us/library/cc262449.aspx

 

 

Comments (55)

CREATING AND DEPLOYING FEATURE IN MOSS

Windows SharePoint Services 3.0 introduces an inherently portable and modular functionality known as feature, which provides a mechanism for defining site elements. 

 A feature is a package of Windows SharePoint Services elements that can be activated for a specific scope and that helps users accomplish a particular goal or task. 

 Features are added to a target site or site collection through a process known as feature activation. The element types that can be defined by a feature include menu commands, link commands, page templates, page instances, list definitions, list instances, event handlers, and workflows. 

 So let’s start writing a feature. The functionality of the feature which we are going to develop is that it adds a menu item “Hello World” in the “Site Actions” menu. Clicking on the menu item “Hello World” will transfer to Google. Our goal is shown in the figure below:

 

 6-3.jpg

 

 The first step is to understand the feature file structure. If you go to “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES” directory, you will see features already existed. Each feature has a file “feature.xml” and other file usually named as “elements.xml”. 

 Now we move to VS 2005 and create a new class library DLL project and name it “HelloWorldFea. Now, it will be intelligent to create the same structure of files as that of WSS 3.0 in the VS 2005. 

 Create a directory “TEMPLATE” in the solution. Inside the “TEMPLATE” directory, create another directory “FEATURE” and lastly, in the “FEATURE” directory, create directory with the same name as that of the project which happens to be “HelloWorldFea”. 

 

6-1.jpg 

 

Now, create a xml file and name it “feature.xml” inside the directory “HelloWorldFea”. In this xml file, we will write the details that will define the high level attributes of the features itself. Add the following XML to the “feature.xml” file. 

<Feature 

Id=“” 

Title=HELLO WORLD FEATURE 

Description=This is hello world feature. 

Scope=Web 

Hidden=FALSE 

ImageUrl=menuprofile.gif 

xmlns=http://schemas.microsoft.com/sharepoint/>   

    <ElementManifests>   

         <ElementManifest Location=elements.xml /> 

    </ElementManifests>

</Feature>  

We describe the attributes of the Feature tag as under: 

Id: GUID which identifies the features uniquely. It can be created by clicking “Tools” menu of VS 2005 and then on “Create GUID”. “Create GUID” window will appear. Select “4 Registry Format (ie. (xxxx …))” option. Click on “Copy” button and paste the GUID against the Id attribute. 

Title: Specifies the title of the feature. 

Description: Specifies the description of the feature. 

Scope: Scope defines the context in which feature is activated and deactivated. It can have four values namely Web, Site, WebApplication and Farm. Web specifies that the feature can be activated and deactivated within the context of site. Site specifies that the feature can be activated and deactivated within the context of the site collection. Same stands for WebApplication and Farm. 

Hidden: Can be set to true or false. In case of true, feature is not visible in the list of available features. It can be activated or deactivated through command line, through custom code, or through an activation dependency with another feature. 

ImageUrl: The image displayed next to the feature in the use interface. The last part is ElementManifests element. The element has inner element ElementManifest which specifies the reference of other XML file. This file defines other elements that make up the feature. In our case, we have one file “elements.xml”. 

Create “elements.xml” file in the “HelloWorlFea” directory. The XML for the file is as under: 

<Elements xmlns=http://schemas.microsoft.com/sharepoint/ >  <CustomAction    Id=SiteActionsToolbar     

 

GroupId=SiteActions   

Location=Microsoft.SharePoint.StandardMenu   

Sequence=100   

Title=Hello World   

Description=A custom menu item added using a feature   

ImageUrl=_layouts/images/menuprofile.gif >   

    <UrlAction Url=http://www.google.com/>     

</CustomAction>

</Elements > 

Id has the name of the menu in which we want to add our menu item. Title and description specifies the text that will appear as title and description. UrlAction states the url of the site where user is redirected when clicked. In our case, it is http://www.google.com. 

The next step is to deploy the feature unto the “FEATURE” directory. For this purpose we create a batch file and name it “deploy.bat”. The contents of the file are: 

@SET TEMPLATEDIR=”C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE”

@SET STSADM=”C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\stsadm” 

Echo Copying filesxcopy /e /y TEMPLATE\* %TEMPLATEDIR% 

Echo Installing feature%STSADM% -o InstallFeature -filename HELLOWorldFea\feature.xml -force 

Echo Reatart IIS Worker Process

IISRESET  

In the end, go to the properties of the project and then to “Build Events” tab. Write the following lines in the “post build event command line window:”  

cd $(ProjectDir)

install.bat 

The first line is required to change the current directory to that of the project directory. The second line runs the batch file to copy the feature files to the correct location and install the feature with the InstallFeature operation of the command-line STSADM.EXE utility. Now go to the “Site Features” page by moving from “Site Actions” to “Site Settings” and clicking on “Site Features” of your site. Here, “Hello World Feature” will be available. Activate it and you will be able to see a menu item added in the “Site Actions” menu. If you fail to find the feature, check the following steps: 

  • “HelloWorldFea” directory is added in the FEATURES directory at the path “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES”

 

  • Run the file “feature.xml” and “element.xml” to check that XML is error free.

If still unable to find the feature, try to deploy manually and see what happen. 

http://msdn2.microsoft.com/en-us/library/ms439657.aspx

Source:

http://www.microsoft.com/learning/en/us/book.aspx?ID=9692&locale=en-us

Comments (6)

Creating a Web Part Using Global Assembly Cache (GAC)

2        Creating a Web Part Using Global Assembly Cache (GAC)

 In this method, we will only describe the different steps with respect to the previous method. Follow the steps 1.1 to 1.4 same as in the previous post and build the project. The code of the project is shown in the figure below:

   

3-1.jpg

2.1   Signing the Assembly

 The next step is of signing the assembly. To do this, you have to move to the properties window of the project as illustrated in the step 1.5. Select the Signing Pane of the properties window and check the “Sign the Assembly” option. Select <New…> from the “Choose a strong name key file:” and give the name that you desired. In our case, we named it “HELLOWORLD” as shown in the figure below:  

3-21.jpg

 

2.2  Build the project

 We will build by pressing F6 or clicking on Build in the tolls menu and then clicking on Build Solution. Build will generate the file in the debug directory of the project. 

2.3  Copying into GAC

 The file HELLASSEMBLY.dll can be found in the debug folder whose path in our case is as fellow C:\Documents and Settings\ffaiz\My Documents\Visual Studio 2005\Projects\HELLOGAC\HELLOGAC\bin\Debug. Depending upon your installation, you can find the file in the debug folder. Copy the file “HELLOASSEMBLY.dll” from this folder and paste it in the GAC folder which is normally found at C:\WINDOWS\assembly. After copying the file in the GAC, copy the public token key as encircled in the figure below: 

  

3-3.jpg

2.4  Adding Reference

 We have to add the reference to the web.config. The file will be located in the folder created by MOSS. In our case, the path of the file is C:\Inetpub\wwwroot\wss\VirtualDirectories\80. We will open the file in the Visual Studio and go to the tag <SafeControls>. Here we will add a new entry for our web part in the <SafeControls> tag which is <SafeControl Assembly=”HELLOASSEMBLY, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ae23d1c2ca8c8a6e” Namespace=”HELLOGAC” TypeName=”*” Safe=”True” />, encircled in the figure below:

 

3-4.jpg

Note here that the public Key Token copied from the GAC has been added in the <SafeControl> tag of the Assembly. 

Rest of the steps is same as that of the previous post. Follow those steps to add the web part in the site. 

Comments (1)

Creating a Web Part Using MOSS BIN DIRECTORY

1         Creating a Web Part Using MOSS BIN Directory

We will start from the Visual Studio 2005 new project window. In the new project window, we will select C# Window application and then, class library. We will name the project “HELLOBIN”.

1-2.jpg

1.1    Adding Reference

The first thing we will do in the class library is to add reference of the name space System.Web. This is done by right clicking on the References link in the solution explorer and then clicking on “Add Reference…”.

 

Clicking on add reference will generate a new pop up window Add Reference. We will select the System.Web namespace, as encircled in the figure below, and click on OK. It will add the System.Web namespace in our project and details of which can be seen in the Reference link.

  

2-2.jpg

   

We will add the names spaces, encircled red in the figure below, in our project so that we can directly use the classes in that namespace without specifying the complete path.

 

3-2.jpg

1.2   Changing Class Name

We will again go to the solution explorer and change the name our class from “Class1” to “HELLOBINCLASS”. This can be done by clicking on the class name in the solution explorer and right click on the class name. This will open a new window from which we will select Rename and change the class name from “Class1” to “HELLOBINCLASS”. As you change the name of the class, a prompt will appear, shown in the figure below, and ask would you like to rename all references to the code element “Class1”? Click Yes.

1.3   Inheriting Class

We will inherit our class from the class WebPart. The path to the class WebPart is System.Web.UI.WebControls.WebParts.WebPArt. We have already added the namespace System.Web.UI.WebControls.WebParts; therefore, we just right the name of the class WebPart for inheritance.

1.4   Overriding Method

We will create a simple program for demonstration purpose. The code will override a method Render. The exact code of the method is shown in the figure below.

4-2.jpg

1.5   Changing Output Path

After writing the code, we will change the out put path setting of the project. For this, we will right click on the project name in the solution explorer and then, we will click on the properties.

 

On clicking the properties, a new window will be appeared. We will select the build pane of the window as shown in the figure below. In the build pane, we will set the out path to the bin directory of the MOSS. In our case, the path is C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin which is encircled in the figure below:

 

5-2.jpg

1.6   Build Project

We will build by pressing F6 or clicking on Build in the tolls menu and then clicking on Build Solution. Build will generate the file HELLOBIN.dll in the bin directory.

 

1.7   Adding Reference

We have to add the reference to the web.config. The file will be located in the folder created by MOSS. In our case, the path of the file is C:\Inetpub\wwwroot\wss\VirtualDirectories\80. We will open the file in the Visual Studio and go to the tag <SafeControls>. Here we will add a new entry for our web part in the <SafeControls> tag which is <SafeControl Assembly=”HELLOBIN” Namespace=”HELLOBIN” TypeName=”*” Safe=”True” />, encircled in the figure below:

 

6-2.jpg

   

After writing the entry, don’t forget to save the web.config file. Becareful while making changes in the web.config file because if this file get corrupted, i am afraid you will be in big trouble. So workaround is that save a copy of file and then make changes so that you have orginal copy of the file intact.

1.8   Adding Web Part in the Web Part Gallery

Now we demonstrate the next phase of adding the web part in the sharepoint site. For this, click on the “Site Action” of your sharepoint main page and click on “Modify All Site Settings” by moving through “Site Settings”.

 

Site Settings page will be opened. Click on the link “Web Parts” under “Galleries”.

 

Web Part Gallery web page will be opened. Click on the “New” to add the web part in the gallery. Clicking on “New” will bring you the list of all the web parts and our web part HELLOCINCLASS will be available in the list. Select the Web Part “HELLOBIN.HELLOCINCLASS” (Name of the namespace followed by the name of the class) and click on the button “Populate Gallery” as shown in the figure below:

7-2.jpg

1.9   Adding Web Part on the Site

After adding the web part in the web part gallery, you can easily add the web part on the desired site. For this, click on the Site Action and then on Edit Page. The page will be open in the edit mode. Click on the link “Add a Web Part” in the space where you want to add the web part.

 

Clicking on “Add a Web Part” will result in a new window which will contain the list of all the web parts. From the list, select the web part you have created.

 

After adding the web part, click on the “Exit Edit Mode” and the web part will be working on the site.

   

   

Comments (2)