Collaboration portal approval workflow - sharepoint

The company I work for has recently taken over a SharePoint 2007 project form another company. The other company created a site using the Collaboration Portal Publishing template. Since this is an internet web site, this is causing me a couple of problems.
By default the approval workflow is not activated on the Pages Libraries of the site, and the client requires the workflow to be active on all of the Pages Libraries. The problem is that the site is massive, and doing this manually will take too long, and because it’s such a large site I can’t recreate it from scratch.
Is there a way I can activate the approval workflow on all the Pages Libraries of the site? Could I maybe change something in the site definition? Or is there a way to activate it programmatically? Then I could create a console app that will recursively iterate through the sites and attach the workflow to the Pages Libraries?

Your can try with this code :
using (MossFramework.DocumentLibraryHelper docLibraryHelper = new MossFramework.DocumentLibraryHelper("SITENAME"))
{
using (SPSite site = new SPSite(docLibraryHelper.MossSiteAddress))
{
SPWeb siteCollection = site.OpenWeb();
siteCollection.AllowUnsafeUpdates = true;
SPFolder folder = siteCollection.GetFolder("Document Centre");
SPList list = siteCollection.Lists["Document Centre"];
Guid wfBaseId = new Guid("{5703E6AC-1C65-440F-88DC-EB65F2C6DF82}");
SPWorkflowAssociation wrkFl = list.WorkflowAssociations.GetAssociationByBaseID(wfBaseId);
foreach (SPListItem spListItem in list.Items)
{
site.WorkflowManager.StartWorkflow(spListItem, wrkFl, wrkFl.AssociationData);
// Error occurs here
}
site.Close();
}
}
or
You can try with this
I hope that helps

Related

Get the SharePoint URL for a Team Project programmatically

I want to find out by coding if a given Team Project has an associated SharePoint. If yes I also want to get the URL for the SharePoint in order to create a specific link to it.
I do not mean the web access of the TFS but the associated SharePoint. Is there a way to find this out without knowing the URL of the SharePoint server that is different from the TFS server?
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Server;
private static string RetrieveProjectPortalBaseAddress(TfsTeamProjectCollection tfs, string teamProject)
{
IRegistration registration = (IRegistration)tfs.GetService(typeof(IRegistration));
RegistrationEntry[] entries = registration.GetRegistrationEntries("TeamProjects");
ServiceInterface endpoint = entries[0].ServiceInterfaces.FirstOrDefault(si => si.Name == teamProject + ":Portal");
return endpoint.Url;
}

Find out where a web part is being used?

Is there an easy way to find out which sites/pages are using a particular web part in SharePoint 2007?
I think the only option would be to write a small tool that iterates over all web sites and pages and checks whether the web part is placed there.
If you know your site and page you can find all webparts of page and check if your webpart is there:
string AbsolutePageUrl = "http://YourSite/Page.aspx";
using (SPSite site = new SPSite(AbsolutePageUrl))
{
using (SPWeb web = site.OpenWeb(AbsolutePageUrl))
{
SPLimitedWebPartManager SpWebPartManger = web.GetLimitedWebPartManager(AbsolutePageUrl,
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
foreach (var webpart in SpWebPartManger.WebParts)
{
if (webpart is MyWebPart)
//your web part is here
}
}
}
but if you want to check this in all sites you have to find all sites and all pages to check for your webpart Existence

WSS 3.0 Site Provisioning

Is there any way to do WSS 3.0 site provisioning? My client's requirement is attributes as variables that will be defined in XML format: Organization Name, Logo, Address, User and Role information. The client should be able to install this web application to any WSS production server by just defining the attributes in the XML file.
Is it possible to to write a utility to parse that well defined XML and provision the site accordingly?
It's possible to provision sites from the object model, but creating entirely customized sites is beyond the scope of a single question. To get you started, you should take a look at the SPWebCollection.Add as well as the SPSiteCollection.Add.
To create a site collection and some subsites into one of your web applications, you could use something like this:
var farm = SPFarm.Local;
var solution = farm.Solutions.GetValue<SPSolution>("YourSolution.wsp");
var application = solution.DeployedWebApplications.First();
var sites = application.Sites;
using(var site = sites.Add("/", "Root Site", "Description", 1033, "YOURTEMPLATE#1", "YOURDOMAIN\SiteCollectionAdmin", "Site Collection Admin", "admin#yourcompany.example")) {
using(var rootWeb = site.RootWeb) {
// Code customizing root site goes here
using (var subSite = rootWeb.Webs.Add("SubSite", "Sub Site", "Description", 1033, "YOURTEMPLATE#2", false, false)) {
// Code customizing sub site goes here
}
}
}
Yes, there are more than one.
Take a look at SharePoint Solution Generator which is in Windows SharePoint Services 3.0 Tools: Visual Studio 2005 Extensions.
You may create a site with all requirements of yours (pages, lists, document libraries...) and then generate a VS project that will create a SharePoint feature with all of your site. Then you may deploy that feature to any WSS production server.
You may alter the VS project to implement the logic to read your attributes from an additional xml file.
If the structure of your site is plain or you can save it as a template you may also write a small console application that reads the attribute xml file and create the site.
Create a regular solution, or use the aforementioned solution generator to generate the .wsp file. Then create a small console application, that expects the variables you mentioned as parameters.
With the code listed above, provision the new sitecollection from that solution, and store the entered parameters (Company name etc.) in the site in a list, or in the SPSite.Properties propertybag, from which you can then read them in custom webparts etc..
The SharePoint Data Population Tool available on CodePlex allows you to define sites with XML.

How to programmatically update content in a SharePoint Web Part?

Does anybody know how to programmatically update the content of any of the standard SharePoint v3 Web Parts?
As an example, put a Link Summary Web Part on a page. Add some links to it. Now, how can I update this information using the WSS API?
I have not found any direct way to do this, my only idea so far is to export the Web Part, (then delete it), modify the generated XML, and import it back. But surely, there must be an easier way?
You can use the SPLimitedWebPartManager class to manipulate Web parts on a Web part page. An instance of this class can be obtained from an SPFile object as follows:
using (SPSite site = new SPSite("<site url>")) // e.g. http://server/sites/asite
using (SPWeb web = site.OpenWeb())
{
SPFile file = web.GetFile("<page url>"); // e.g. /sites/asite/default.aspx
SPLimitedWebPartManager lwpm = file.GetLimitedWebPartManager();
SPLimitedWebPartCollection webParts = lwpm.WebParts;
WebPart wp = webParts[<id, index or Guid>];
// Add your code to update the Web Part
lwpm.SaveChanges(wp);
}
You can also add or delete web parts with the SPLimitedWebPartManager.
You will probably need to call SPWeb.GetWebPartCollection and use the webpart collection to mess with the WebParts thusly

How do I force a new site collection to inherit a master page?

I have some code that creates a new site in SharePoint. Upon browsing to the newly created site, a File Not Found error is thrown. If you browse to /_layouts/ChangeSiteMasterPage.aspx you can select a new site master & system master page, and the site works fine. This kb article describes my symptoms perfectly: http://support.microsoft.com/kb/936908
My problem is that of the two (maybe three?) solutions given, only one works. If I manually select the new master pages it works fine. The second workaround is to activate the publishing feature on the new site. This does not fix anything.
There is also a recommendation to staple the publishing feature to the site definition I am using for the new site. In my case, this is STS#1 (the blank site), and stapling the publishing feature does not alleviate my problem.
Anyone have an idea of how I can get the correct master page sorted out?
We do this through a delegate control. In the OnLoad we call the following method:
private void ConfigureMasterPage(SPWeb web)
{
string masterURL = string.Empty;
masterURL = web.Site.ServerRelativeUrl + "/_catalogs/masterpage/XXX.master";
masterURL = masterURL.Replace("//", "/");
web.MasterUrl = masterURL;
web.CustomMasterUrl = masterURL;
web.Update();
}
Dont forget to do a dispose of the SPSIte and SPWeb objects and You will have to set AllowUnsafeUpdates to true.
Hope this helps
Turns out I just needed to change the master template in one of the generated sites and then save that as a template. I deleted the broken template and put this in its place. Now all the generated sites work fine.

Resources