Saving a list as a list template & creating lists from custom template using PowerShell

Posted on Updated on

  • To save list as a template use following code

$site = get-spsite("http://testsite")

$web = $site.RootWeb

$list = $web.Lists["Announcements"]

SharePoint $list.SaveAsTemplate() PowerShell Command use following parameters.

$list.SaveAsTemplate(“Template Name”,”Template Title”,”Template Description”,1)

In the forth parameter of SaveAsTemplate(), if you want to save the specified site as template along with data use 1, otherwise use 0.

Eg:- $list.SaveAsTemplate("TestListTemplate.stp", "TestListTemplate", "Test List Template", $false)

 

  • Creating a new list from the template created.

$listTemplates = $site.GetCustomListTemplates($web)

$web.Lists.Add("TestList", "Test List", $listTemplates["TestListTemplate"])

Advertisements

Configure SharePoint to send email using Gmail Account

Posted on Updated on

Steps

  1. configure SMTP service on Windows 2008 to forward emails to Gmail servers which will send the actual emails
  2. configure SharePoint Server 2010 to send emails through your Gmail account
Configure the SMTP Server

Go to Control Panel, click on Turn Windows features on or off, go to Features, click Add Features, select SMTP Server from the list, click Add Required Role Services, click Next (a few times), click Install

  • Open Internet Information Services (IIS) 6.0 Manager under Administrative Tools, expand the node with your local computer name on it, right click on SMTP Virtual Server, click on Properties
  • on the Access tab, click on Relay …, select All except the list bellow and click OK
  • on the Delivery tab, click on Outbound Security, on the new window that opens select Basic Authentication and type your Gmail (or Google Apps) email and password in the Username and Password fields, and also select TLS encryption
  • on the Delivery tab, click Outbound connections… and in the new window that opens change TCP port to 587
  • once again in the Delivery tab, click on Advanced and in the new window that opens, in the Smart host field type smtp.gmail.com and click OK
  • click Apply, click OK.
  • Make sure POP is enabled for you Gmail account (it’s under Settings -> Forwarding and POP/IMAP).

 

configure SharePoint server to send emails using Gmail account
  • open SharePoint Central Administration, go to System Settings, go to Configure outgoing e-mail settings
  • type your computer name in the field Outbound SMTP server (I have also tried 127.0.0.1 and localhost but they did not work for me)
  • type your Gmail email address in field From address

  • click OK

Save site as template in SharePoint 2010

Posted on Updated on

  • Go to Site Actions  –> Site Settings –> Manage site features under Site Actions.
  • Deactivate the SharePoint Server Publishing feature, then go back to the Site Settings page.
  • You should now see the save as site template link.
  • After you save the template, Activate the SharePoint Server Publishing feature.

Convert Your Virtual PC’s To VMware Workstation

Posted on Updated on

http://www.winimage.com/

You Can Use this Tool to convert VHD disk to VMware(vmdk) disk .. Smile

How to resolve "The type or namespace name ‘SharePoint’ does not exist in the namespace ‘Microsoft’ Error

Posted on Updated on

  • Go to the Solution explorer.
  • Right click on the Solution Explorer and click Properties.
  • Select Application Tab, by default Target Framework will be .Net Framework 3.5 Client Profile change it to .Net Framework 3.5.
    image3.gif
  • Once you change the Target Framework “Target Framework Change “wizard will pop up.
  • Click Yes.
  • Go the Build tab and change the Platform Target to x64.
  • Hit F5 now you will be able to debug successfully.

Create a Custom Site Workflow Activity Using C#

Posted on Updated on


First, create a project to hold and test the custom workflow activity.

To create a site workflow custom activity project
  1. Display the New Project dialog box by pointing to New on the File menu, and then click New Project.

  2. Expand the SharePoint node under either Visual C# or Visual Basic, and then click 2010.

  3. In the Templates pane, select Sequential Workflow.

  4. In the Name box, type AnnouncementBackup and then click OK.

    The SharePoint Customization Wizard appears.

  5. In the What is the local site you want to use for debugging? page, click Next to accept the default site.

    This step also sets the trust level for the solution as farm solution, the only available option for workflow projects.

  6. In the Specify the workflow name for debugging page, accept the default name (AnnouncementBackup – Workflow1). Change the workflow template type to Site Workflow and then click Next.

  7. Click Finish to accept the remaining default settings.

Adding a Custom Workflow Activity Class


Next, add a class to the project to contain the code for the custom workflow activity.

To add a custom workflow activity class
  1. Click Add New Item on the Project menu to display the Add New Item dialog box.

  2. In the Installed Templates tree view, click the Code node and then click Class in the list of project item templates. Use the default name Class1.

  3. Replace all of the code in Class1 with the following:

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; namespace AnnouncementBackup { // This custom activity will back up all of the announcements in // the Announcements list on the SharePoint site. public class Class1 : System.Workflow.ComponentModel.Activity { public Class1() { } // Triggers when the activity is executed. protected override System.Workflow.ComponentModel.ActivityExecutionStatus Execute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { try { // Get a reference to the SharePoint site. SPSite site = new SPSite("http://" + System.Environment.MachineName); SPWeb web = site.OpenWeb("/"); // Reference the original Announcements list. SPList aList = web.GetList("/Lists/Announcements"); // If the Announcements Backup list already exists, delete it. try { SPList bList = web.GetList("/Lists/Announcements Backup"); bList.Delete(); } catch { } // Create a new backup Announcements list and reference it. Guid newAnnID = web.Lists.Add("Announcements Backup", "A backup Announcements list.", SPListTemplateType.Announcements); SPList bakList = web.Lists[newAnnID]; // Copy announcements from original to backup Announcements list. foreach (SPListItem item in aList.Items) { SPListItem newAnnItem = bakList.Items.Add(); foreach (SPField field in aList.Fields) { if (!field.ReadOnlyField) newAnnItem[field.Id] = item[field.Id]; } newAnnItem.Update(); } // Put the Backup Announcements list on the QuickLaunch bar. bakList.OnQuickLaunch = true; bakList.Update(); } catch (Exception errx) { System.Diagnostics.Debug.WriteLine("Error: " + errx.ToString()); } return base.Execute(executionContext); } } }

  4. Save the project and then click Build Solution on the Build menu.

  5. Class1 appears as a custom action in the Toolbox under the SharePoint Workflow tab in the Toolbox.

Adding the Custom Activity to the Site Workflow


Next, add an activity to the Workflow to contain the custom code.

To add a custom activity to the site Workflow
  1. Open Workflow1 in the workflow designer in design view.

  2. Click and drag Class1 from the Toolbox and drop it under the onWorkflowActivated1 activity.

  3. Save the project.

Testing the Site Workflow Custom Activity


Next, run the project and start the site workflow. The custom activity creates a backup Announcements list and copies the contents from the current Announcements list into it. The code also checks whether a backup list already exists before creating one. If a backup list already exists, it is deleted. The code also adds a link to the new list on the SharePoint site’s QuickLaunch bar.

To test the site workflow custom activity
  1. Press F5 to run the project and deploy it to SharePoint.

  2. On the QuickLaunch bar, click Lists to display all of the lists available in the SharePoint site. Notice there is only one list for announcements named Announcements.

  3. At the top of the SharePoint Web page, click the Site Actions button and then click Site Workflows.

  4. Under the Start a New Workflow section, click the link for AnnouncementBackup – Workflow1. This starts the site workflow and runs the code in the custom action.

  5. Click the link called Announcements Backup that appears on the QuickLaunch bar. Notice that all of the announcements that are contained in the Announcements list have been copied to this new list.

Original Reference

SharePoint: Create Custom Workflow Activities Using VS 2008 (Video)

Run SharePoint 2010 on Windows 7

Posted on Updated on

  • Copy the SharePoint Foundation.exe (or setup.exe) installation file to a folder on the computer where you are installing SharePoint and doing your development, such as in the following path:

    c:\SharePointFiles

  • Extract the installation files by opening a Command Prompt window, and then typing the following command at the directory location of the folder where you copied the installation files in the previous step.

    For SharePoint Foundation 2010:

    c:\SharePointFiles\SharePoint /extract:c:\SharePointFiles

    For SharePoint Server 2010:

    c:\SharePointFiles\OfficeServer /extract:c:\SharePointFiles

  • Using a text editor such as Notepad, open the installation configuration file, config.xml, located in the following path: c:\SharePointFiles\files\Setup\config.xml

    Add this line inside the <configuration> tag:

    XML

    <Setting Id="AllowWindowsClientInstall" Value="True"/>
  • Save the configuration file.

  • Review the complete configuration file. It now looks similar to the following for SharePoint Foundation 2010. The complete configuration file will be longer for SharePoint Server 2010 (and therefore the text below cannot replace the contents of that file), but should use the same setting for the AllowWindowsClientInstall attribute.

    XML

    <Configuration>
      <Package Id="sts">
        <Setting Id="SETUPTYPE" Value="CLEAN_INSTALL" />
      </Package>
      <DATADIR Value="%CommonProgramFiles%\Microsoft Shared\Web Server
       Extensions\14\Data" />
      <Logging Type="verbose" Path="%temp%" Template="Microsoft Windows
       SharePoint Services 4.0 Setup *.log" />
      <PIDKEY Value="PIDKey Value" />
      <Setting Id="UsingUIInstallMode" Value="1" />
      <Setting Id="SETUP_REBOOT" Value="Never" />
      <Setting Id="AllowWindowsClientInstall" Value="True"/>
    </Configuration>