using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace Retrive_Solutions { class SolutionBackup { static void Main(string[] args) { SPSolutionCollection AllSolutions = SPFarm.Local.Solutions; foreach (SPSolution Solution in AllSolutions) { SPPersistedFile wspFile = Solution.SolutionFile; wspFile.SaveAs("C:\\Solutions\\" + Solution.Name); } } } } The same also can be achieved using PowerShell so no need to write any OM code. Here is the PowerShell script to acheive the same:[Void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local $path = Split-Path $MyInvocation.MyCommand.Path [Void]( ni "$path\Solutions" -type Directory -force ) $farm.Solutions |% { Write-Host $_.Name $solution = $_.SolutionFile $solution.SaveAs("$path\solutions\$($solution.Name)") }
| Online Training On SharePoint |
Showing posts with label code example of SharePoint Object model. Show all posts
Showing posts with label code example of SharePoint Object model. Show all posts
Saturday, 26 February 2011
Retriving SharePoint WSP Files from Config DB using SharePoint Object Model and PowerShell
WSP files are the preferred way of deploying the new functionlaity in SharePoint. WSP files are stored in the Config DB. If you need to extract these files you can do that by using the SharePoint Object Model Code. The following code snippet will retrive all the solutions from the config DB and will place them in the specified location:
Friday, 4 June 2010
Start SharePoint Workflows with Intiation Parameters Programatically
To start the SharePoint workflows programatically by passing the initiation parameters following code can be used:
static void Main(string[] args) { using (SPSite spSite = new SPSite("http://localhost")) { using (SPWeb spWeb = spSite.RootWeb) { SPWorkflowAssociation workflowAssociation = spWeb.WorkflowAssociations.GetAssociationByName("WorkflowDemo",CultureInfo.InvariantCulture); if (workflowAssociation != null) { SPWorkflow siteWorkflow = spSite.WorkflowManager.StartWorkflow(spSite, workflowAssociation, "<Data><CompanyID>zzz</CompanyID></Data>", SPWorkflowRunOptions.Asynchronous); } } } Console.WriteLine("Workflow Started with the Initiation Parameter"); Console.Read(); }
Friday, 9 October 2009
Creating new topics in Discussion Board and replies using Object Model
We had a requirments to create new discussions and the responses using SharePoint object model. Here is the code which we used to create this.
SPList oList = oWeb.Lists["My Discussion"]; SPListItemCollection myListItems = oList.Items; SPListItem oFirstItem = SPUtility.CreateNewDiscussion(myListItems, "Talk about Task X"); oFirstItem["Body"] = "What say you about task X?"; oFirstItem.Update(); SPListItem oReply1 = SPUtility.CreateNewDiscussionReply(oFirstItem); oReply1["Body"] = "my reply @" + DateTime.Now.ToString(); oReply1.Update();
Subscribe to:
Posts (Atom)